2016-04-12 12 views
0

2つの関数を作成しました。私は "createNewOne"から "findTitleNew"を呼び出します。 "createNewOne"関数でドキュメントに到達しましたが、 "findTitleNew"関数に戻ると "findTitleNew"で見つかったドキュメントが失われました そのドキュメントを失うことなく続けるにはどうすればいいですか? 注:これらの機能をアプリケーションで複数回使用するため、この機能は一般的です。SSJSライブラリのXPages関数がドキュメントとして返されない

<xp:button value="Create" id="btnCreate"> 
      <xp:eventHandler event="onclick" submit="true" 
       refreshMode="complete" immediate="false" save="true"> 
       <xp:this.action><![CDATA[#{javascript:createNewDoc(document1)}]]></xp:this.action> 
      </xp:eventHandler> 
     </xp:button> 


function findTitleNew(currDoc:NotesXSPDocument) 
{ 
    try 
    { 
     var dbOther1:NotesDatabase = session.getDatabase(database.getServer(),sessionScope.kontak_db_Path); 
     if (currDoc.getItemValueString("UNID")!="") 
     { 
      var otherDoc:NotesDocument = dbOther1.getDocumentByUNID(currDoc.getItemValueString("UNID")) 
     } 
    } 
    catch (e) 
    { 
     requestScope.status = e.toString(); 
    } 
} 

function createNewOne(docThis:NotesXSPDocument) 
{ 
    try 
    { 
     //do stafff 
     findTitleNew(docThis) 
     //do stafff 
    } 

    catch (e) 
    { 
     requestScope.status = e.toString(); 
    } 
} 

ご迷惑をおかけして申し訳ございません。
Cumhurアタ

答えて

1

私SSJSは本当に錆びていると私は正確に何をしたい教えするのは少し難しいですが あなたが言う:その文書を失うことなく継続する方法findTitleNew 『「私はで発見された文書を失いました』 ? "

" findTitleNew "関数は何も返しません。あなたがそこに文書を取得するのであれば、あなたはそれに取り組むことができますが、あなたは次に見つかった文書

if (currDoc.getItemValueString("UNID")!="") 
     { 
      var otherDoc:NotesDocument = dbOther1.getDocumentByUNID(currDoc.getItemValueString("UNID")) 
return otherDoc; 
     } 

を返す必要「createNewOne()」関数内での移動を行いたい場合:

function createNewOne(docThis:NotesXSPDocument) 
{ 
    try 
    { 
     //do stafff 
     var returnDoc = findTitleNew(docThis); 
     if (null != returnDoc) { 
      // do stuff with returnDoc here... 
     } 
     //do stafff 
    } 

    catch (e) 
    { 
     requestScope.status = e.toString(); 
    } 
} 
0

変数otherDocの範囲です。

変数をvar otherDocと定義しました。 The scope of a variable declared with var is its current execution context, which is either the enclosing function or, for variables declared outside any function, global.
var otherDocは関数内で定義されているため、関数内でのみ「存続」します。つまり、otherDocは機能外では使用できません。

otherDocに値を割り当てることはできません。この場合、グローバルに利用可能となる。しかし、これはお勧めできません。

最も良い方法は、彼の答えにDavidが示すようにreturn otherDocで変数を返すことです。

関連する問題