You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetSuite SuiteScript2.0:套件商品成员替换脚本问题求助

Fixing Your NetSuite SuiteScript 2.0 Kit Member Replacement Script

Hey David, let's break down and fix both issues you're facing with your workflow action script for updating Kit/Package items.


Issue 1: Can't Use Field Tags Directly as Values

First off, the {custitem_burkett_bestmemberitem} syntax you tried is for NetSuite's FreeMarker templating (like saved searches or email templates)—it doesn't work in SuiteScript. To pull the value of that custom field, you need to use the currentRecord.getValue() method. You also had a couple of case-sensitive syntax mistakes in your API calls:

  • NetSuite SuiteScript 2.0 methods use camelCase (lowercase first letter), so SetCurrentSublistValue should be setCurrentSublistValue
  • The parameter name Value needs to be lowercase value (API parameters are strict about case)

Issue 2: "No Matching Audience" Error

This error means your workflow action script's deployment isn't configured to run on Kit/Package records. Here's how to fix it:

  • Navigate to your script deployment record (Customization > Scripting > Script Deployments)
  • Find your "Set Best Member Item" deployment
  • In the Audience tab:
    • Under Applies To, make sure Inventory Item is selected (Kit/Package is a sub-type of Inventory Item)
    • To narrow it down specifically to Kit/Package items, check the Item Subtype filter and select Kit/Package
  • Save the deployment, then re-test your workflow

Corrected Full Script

I updated your script to include missing logic for removing existing kit members, fixed all syntax issues, and properly fetched the custom field value:

define(["N/currentRecord"], function(currentRecord) {
    var rec = currentRecord.get();

    function replaceKitMembers() {
        // Step 1: Remove all existing kit members from the item sublist
        var lineCount = rec.getLineCount({ sublistId: "item" });
        // Delete lines from last to first to avoid index shifting problems
        for (var i = lineCount - 1; i >= 0; i--) {
            rec.removeLine({
                sublistId: "item",
                line: i
            });
        }

        // Step 2: Get the ID of the best member item from the custom field
        var bestMemberItemId = rec.getValue({
            fieldId: "custitem_burkett_bestmemberitem"
        });

        // Only proceed if we have a valid item ID
        if (bestMemberItemId) {
            // Step 3: Insert the new kit member
            rec.insertLine({
                sublistId: "item",
                line: 0 // Insert at the first position
            });
            rec.setCurrentSublistValue({
                sublistId: "item",
                fieldId: "item",
                value: bestMemberItemId
            });
            rec.setCurrentSublistValue({
                sublistId: "item",
                fieldId: "quantity",
                value: 1
            });
            rec.commitLine({ sublistId: "item" });
        }
    }

    // Run the function when the script executes
    replaceKitMembers();
});

Key Improvements:

  • Added logic to remove all existing kit members (critical for fully replacing the kit contents)
  • Properly fetches the custom field value using currentRecord.getValue()
  • Fixed all case-sensitive API method/parameter names
  • Added a check to avoid inserting empty/invalid items
  • Deletes lines from last to first to prevent index errors when removing multiple entries

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 08:07:37