機械翻訳について

製品ラインの価格を更新するにはどうすればよいですか?

Groovyスクリプトを使用して、選択した価格台帳から製品の定価を取得し、製品明細の「金額」フィールドにその値をスタンプすることもできます。

  1. アクティブなサンドボックスで作業していることを確認します。

  2. アプリケーション・コンポーザで、「標準オブジェクト」「商談」「商談売上」「サーバー・スクリプト」にナビゲートします。

  3. 「トリガー」タブを選択します。

  4. サーバー・スクリプト商談売上ページの「フィールド・トリガー」セクションで、「新規トリガーの追加」アイコンを選択します。 ページが「フィールド・トリガーの作成」ページに変わり、「トリガー・タイプ」フィールドはAfter Field changedにデフォルト設定されます。

  5. 「フィールド・トリガーの作成」ページで、「フィールド名」に対して「製品」を選択します。

    ノート: リストに「製品」のインスタンスが2つある場合は、最初のインスタンスを選択します。
  6. 「トリガー名」フィールドにFetchPriceと入力します。

  7. 「トリガー定義」リージョンに、次のスクリプトを入力します。

    //Get the ID of the item:
    def var_InventoryItemId = nvl(getAttribute('InventoryItemId'), (long) 0) 
    //Get the ID of the price book (this is useful if you have multiple price books):
    def var_DCL_PriceBook = Opportunity?.PriceBook_Id_c // 
    //PriceBook is a dynamic choice list on the opportunity.
    //Make a view of the PriceBookItem object, since that's where the prices for items are stored:
    def view_PriceBookItem = newView('PriceBookItem')
    def view_Criteria = newViewCriteria(view_PriceBookItem)
    def view_criteria_row = view_Criteria.createRow()
    
    //Define the first sort criteria. Basically, find all records in PriceBookItem that match the ID of the InventoryItemId on revenue.
    def view_condition = view_criteria_row.ensureCriteriaItem('InvItemId')
    view_condition.setOperator('=')
    view_condition.setValue(var_InventoryItemId)
    
    //Define the second sort criteria. If there are multiple price books that contain the same item with different prices, get the price of the item corresponding to the price book selected in the dynamic choice list on the opportunity.
    def view_condition_1 = view_criteria_row.ensureCriteriaItem('PricebookId')
    view_condition_1.setOperator('=')
    view_condition_1.setValue(var_DCL_PriceBook)
    
    //Execute the sort and query the records:
    view_Criteria.insertRow(view_criteria_row)
    view_PriceBookItem.appendViewCriteria(view_Criteria)
    view_PriceBookItem.setMaxFetchSize(1400) //1,400 is the number of records in the system; change this number according to your system records.
    view_PriceBookItem.executeQuery()
    
    def var_price // This is a variable that will hold the price from PriceBookItem
    while(view_PriceBookItem.hasNext()){
    def var_Row = view_PriceBookItem.next()
    
    //Get the price from PriceBookItem for the item you want:
    var_price = var_Row.getAttribute('ListPrice') 
    }
    //Assign the price to the revenue field UnitPrice:
    setAttribute('UnitPrice',var_price) 
  8. 「保存して閉じる」をクリックします。「トリガー」セクションのFieldNameがInventoryItemIdと表示されていることを確認します。

  9. 変更をテストし、サンドボックスを公開します。