2016-05-20 4 views
0

私は購入レコードの契約レコードから値を探していましたが、値があるフィールドを取得できませんでした。以下はそのコードです。私はこのコードを契約記録に適用しており、機能は提出前のものです。 私は間違った方法で検索を適用していると思います。事前に購買発注レコードの契約レコードからfileldの値を検索したい

function srchfield() 
{ 

     var recordid = nlapiGetRecordId() //retunrs the contract id 
     nlapiLogExecution('DEBUG', 'recordid ', recordid); 

     var recordtype = nlapiGetRecordType();  //retunrs the contract recordtype = jobs 
     nlapiLogExecution('DEBUG', 'RecordType', recordtype); 

     var loadrecord = nlapiLoadRecord(recordtype, recordid); //loads the record 
     nlapiLogExecution('DEBUG', 'Load Record', loadrecord); 

     var contractname = nlapiGetFieldValue('entityid'); //returs the value of the field contractname whose fieldid is = entityid 
     nlapiLogExecution('DEBUG', 'ContractName ', contractname); 


    var filters = new Array(); 
     new nlobjSearchFilter('entityid', null, 'anyof', contractname); // entityid is field id in contract Record and contractname is defined above for contract record 

      // nlapiLogExecution('DEBUG', 'SearchFilter', filters); 

    var columns = new Array(); 
    new nlobjSearchColumn('custbodycontract'); // custbodycontractis field id in PO Record 


    var searchresults = nlapiSearchRecord('purchaseorder', null, filters, columns); 


for (var i = 0; searchresults != null && i < searchresults.length; i++) 
{ 
    var searchresult = searchresults[ i ]; 
    var record = searchresult.getId(); 
    var rectype = searchresult.getRecordType(); 
    var cntrct_name= searchresult.getValue('custbodycontract'); 

} 

} 

おかげ

+0

明確にする:これらの契約エンティティによってPOを検索していますが、別のPOフィールド「custbodycontract」があります。それは何を保持していますか? – TonyH

+0

これは、契約フィールドからエンティティを検索しているPOのフィールドのフィールドIDです。 – Galdiator

+0

コントラクト名 – Galdiator

答えて

0

****アップデート:私は提供コメントに基づいて私の答えを完了しました。最後のセクションをご覧ください。私はそれが助けて欲しいありがとう!***


**これをさらに説明すると、私はあなたにスニペットを提供するかもしれません。私が正しくあなたのコードを理解していれば

を教えてください、これらは、あなたがやっていることであり、あなたがやりたい:

  • ご契約レコードはネイティブのエンティティレコードです - プロジェクト/仕事。あなたの機能的なコンサルタントが契約するために名前が変更されました。
  • 提出して契約(プロジェクト/ジョブ)レコードに展開する前に、ユーザーイベントスクリプト(SuiteScript 1.0)があります。
  • 契約レコード(この場合は契約名(entityid)を使用)を使用して、ヘッダで「custbodycontract」を取得するPOを検索したかった
  • 次に、あなたはPOに関連して契約レコードがどのようになっているのか説明できますか? POには、契約レコードの結合として使用できるフィールド(ネイティブ/カスタム)がありますか?


    次に、このベストプラクティスを空き金としてメモしてください。
    1. スクリプトを最適化する。 beforesubmitでnlapiLoadRecordを使用する必要はありません。以下のベストプラクティスをご覧ください。
              - beforesubmitを使用し、スクリプト展開レコードの値を取得または設定する場合は、nlapiGet **およびnlapiSet ** APIを使用します。
              - 別のレコードのサブリストの値を取得して設定している場合は、beforesubmitでnlapiLoadRecordを使用してください。しかし、ラインレベル(異なるレコード)で値を取得している場合は、最初のnlapiSearchRecordを使用します。必要なものが得られない場合は、nlapiLoadRecordを使用してください。
              - デプロイされたレコードと異なるレコードの行レベルで値を設定して取得している場合は、後に、nlapiLoadRecordを使用してください。あなたがレベルでのみ価値を得ているなら、beforesubmitで同じ練習。
              - ヘッダーから値を取得するためにnlapiLookUpを使用し、設定している場合はnlapiSubmitFieldを使用してください。 nlapiLoadRecordは、必要なものを提供しない場合にのみ使用してください。


      ****これは、何が必要かもしれない...

function srchfield() 
{ 
    var stRecordid = nlapiGetRecordId(); /*retunrs the contract id*/ 
    nlapiLogExecution('DEBUG', 'recordid ', stRecordid); 

    var stRecordtype = nlapiGetRecordType(); /*retunrs the contract recordtype = jobs*/ 
    nlapiLogExecution('DEBUG', 'RecordType', stRecordtype); 

    var stContractname = nlapiGetFieldValue('entityid'); /*returs the value of the field contractname whose fieldid is = entityid*/ 
    nlapiLogExecution('DEBUG', 'ContractName ', stContractname); 

    var arrFilters = new Array(); 
    arrFilters.push(new nlobjSearchFilter('type', null, 'anyof', 
     [ 
      'PurchOrd' 
     ])); /*As best practice, instead of directly searching on POs, add filter for transaction type since you might use this later in other transaction.*/ 
    arrFilters.push(new nlobjSearchFilter('mainline', null, 'is', 'T')); /*This is to exclude line level results*/ 
    arrFilters.push(new nlobjSearchFilter('custbodycontract', null, 'is', stContractname)); 

    var arrColumns = new Array(); 
    arrColumns.push(new nlobjSearchColumn('trandate')); /*I just wanted to include this column on the result. :)*/ 
    arrColumns.push(new nlobjSearchColumn('type')); /*I just wanted to include this column on the result. :)*/ 
    arrColumns.push(new nlobjSearchColumn('tranid')); /*I just wanted to include this column on the result. :)*/ 
    arrColumns.push(new nlobjSearchColumn('custbodycontract')); /*This is what you need.*/ 

    var arrSearchresults = nlapiSearchRecord('transaction', null, arrFilters, arrColumns); 
for (var i = 0; arrSearchresults != null && i < arrSearchresults.length; i++) 
{ 
    var objResult = arrSearchresults[i]; 
    var stRecId = objResult.getId(); 
    var stRecType = objResult.getRecordType(); 
    var stCntrctName = objResult.getValue('custbodycontract'); 
} 
+0

hello 契約レコードとPOレコードは、契約名で相互に接続されています。契約レコードのこのフィールドの内部IDは "entityid"で、POレコードの内部IDは "custbodycontract" – Galdiator

+0

です。その後beforesubmitユーザーイベントが契約レコードに展開されます。右?次に、entityidを使ってPOを検索しますか? –

+0

次にentityidがレコードの内部IDではなくテキスト値を与えることに注意してください。したがって、私は "custbodycontract"がフリーフォームのテキストフィールド型であると推測します。ご確認ください。 –

0

私はあなたのコードに気づくの問題は、フィルタの作成です。
nlobjSearchFilterをインスタンス化しましたが、配列にプッシュしませんでした。だから基本的に、あなたはフィルタなしで検索している。
あなたの検索条件は完全だと思います。
次のコードを試してください。ところで、custbodycontractのフィールドタイプは、契約レコードのエンティティIDと適切に比較するためのフリーフォームテキストであることを確認してください。

function srchfield() 
{ 
var stRecordid = nlapiGetRecordId(); /*retunrs the contract id*/ 
nlapiLogExecution('DEBUG', 'recordid ', stRecordid); 

var stRecordtype = nlapiGetRecordType(); /*retunrs the contract recordtype = jobs*/ 
nlapiLogExecution('DEBUG', 'RecordType', stRecordtype); 

var stContractname = nlapiGetFieldValue('entityid'); /*returs the value of the field contractname whose fieldid is = entityid*/ 
nlapiLogExecution('DEBUG', 'ContractName ', stContractname); 

var arrFilters = new Array(); 
arrFilters.push(new nlobjSearchFilter('type', null, 'anyof', 
    [ 
     'PurchOrd' 
    ])); /*As best practice, instead of directly searching on POs, add filter for transaction type since you might use this later in other transaction.*/ 
arrFilters.push(new nlobjSearchFilter('mainline', null, 'is', 'T')); /*This is to exclude line level results*/ 
arrFilters.push(new nlobjSearchFilter('custbodycontract', null, 'is', stContractname)); 

var arrColumns = new Array(); 
arrColumns.push(new nlobjSearchColumn('trandate')); /*I just wanted to include this column on the result. :)*/ 
arrColumns.push(new nlobjSearchColumn('type')); /*I just wanted to include this column on the result. :)*/ 
arrColumns.push(new nlobjSearchColumn('tranid')); /*I just wanted to include this column on the result. :)*/ 
arrColumns.push(new nlobjSearchColumn('custbodycontract')); /*This is what you need.*/ 

var arrSearchresults = nlapiSearchRecord('transaction', null, arrFilters, arrColumns); 
for (var i = 0; arrSearchresults != null && i < arrSearchresults.length; i++) 
{ 
    var objResult = arrSearchresults[i]; 
    var stRecId = objResult.getId(); 
    var stRecType = objResult.getRecordType(); 
    var stCntrctName = objResult.getValue('custbodycontract'); 
} 
} 
関連する問題