ディスカッション

NetSuiteの保存検索やレポートをマスターするための究極のガイドである分析センターを使用して、データの力を最大限に活用しましょう。複雑さを単純化し、組織の真の可能性を解き放ちます。今すぐ分析センターに参加して、新たな高みを目指しましょう!
New AI Community Guidelines. Please review and follow them to ensure AI use stays safe, accurate, and compliant.
Update: Narrative Insights has been restored and is now available.

Narrative Insights is Temporarily Unavailable due to an Infrastructure Issue. Learn how This Impacts Your Account and What to Expect While the Feature is Disabled.

SuiteScript >子レコードが条件を満たしている場合、子レコードを親レコードに添付

適用

製品: NetSuite 2021.1

 



シナリオ

特定の条件を満たす場合にのみ子レコードが添付されるように、子レコードを親レコードに添付するユーザーを制限します。

例: 条件は、子レコードと親レコードの両方のカスタム・フィールド (例:工場フィールド) が同じ場合のみ、子レコードが親レコードに添付可能とします。 工場フィールドが 2 つのレコード間で等しくない場合は、nlobjRecord.setFieldValue を使用して子レコードの親フィールドを空白に設定し、子が親に関連付けられないようにします。

注`:スクリプトは子レコードにデプロイする必要があります。



解決策

サンプルスクリプト

SuiteScript 2.0:

 
function afterSubmit(scriptContext) { 
  var id = record.id; 
  //子レコードをロード 
  var rec = record.record.load({ 
    type: 'customrecord_child', 
    id: id 
  }); 
  //子レコードでの工場フィールドを取得 
  var child_cust = rec.getValue({ 
    fieldId: 'custrecord_child_factory' 
  }); 
 
  //子レコードでの親IDを取得 
  var par_id = rec.getValue({ 
    fieldId: 'custrecord_parent_id' 
  }); 
 
  //親フィールドでの工場フィールドを取得 
  var par_cust = search.lookupFields({ 
    type: customrecord_parent, 
    id: par_id, 
    columns: ['custrecord_parent_factory'] 
  }); 
 
  if (child_cust != par_cust) { 
    //子レコードでの親IDを空白に設定 
    rec.setValue({ 
      fieldId: 'custrecord_parent_id', 
      value: '' 
    }); 
  } 
  rec.save(); 
} 

 

SuiteScript 1.0:

 
function afterSubmit() { 
  var id = nlapiGetRecordId(); 
  //子レコードをロード 
  var rec = nlapiLoadRecord('customrecord_child', id); 
 
  //子レコードでの工場フィールドを取得 
  var child_cust = rec.getFieldValue('custrecord_child_factory'); 
 
  //子レコードでの親IDを取得 
  var par_id = rec.getFieldValue('custrecord_parent_id'); 
 
  //親フィールドでの工場フィールドを取得 
  var par_cust = nlapiLookupField('customrecord_parent', par_id, 'custrecord_parent_factory'); 
 
  if (child_cust != par_cust) { 
    //子レコードでの親IDを空白に設定 
    rec.setFieldValue('custrecord_parent_id', ''); 
  } 
  nlapiSubmitRecord(rec); 
} 

ようこそ!

サインイン

完全な詳細を表示するには、サインインしてください。

登録

アカウントがありませんか?ここをクリックして始めましょう!

リーダーボード

コミュニティの達人

第2四半期 (4月~6月 2026)

今週のリーダー

今月のリーダー

歴代リーダー