【问题标题】:Automatically Filtering Items By Vendor During Creation of a Record在创建记录期间按供应商自动过滤项目
【发布时间】:2017-01-06 08:02:16
【问题描述】:

我有一组正在使用的脚本,它们可以相互交互。我使用客户端、用户事件和套件脚本来创建一个按钮,按下该按钮会打开一个弹出窗口,其中包含由供应商过滤的项目列表。

当我在编辑时它工作正常,但是当我在创建记录时使用它时会出现问题。由于要创建的记录没有供应商或 ID,我无法按供应商检索项目。我要做的是让 Suitelet 从保存之前输入的供应商字段中检索信息。因此,我可以按供应商过滤所有项目并一次性添加必要的项目。这可能吗?我可以在提交之前访问这些信息吗?

以下是客户端和 Suitelet。用户事件只是对套件的调用,所以为了简洁起见,我省略了它。

客户端脚本

function addItemButtonCallback(data){
    nlapiSelectNewLineItem('item');
    nlapiSetCurrentLineItemValue('item', 'item', data);
    nlapiCommitLineItem('inventoryitem');
}

function addItemButton() {
    var id = nlapiGetFieldValue('id');
    if (id != "") {
        var url = nlapiResolveURL('SUITELET', 'customscript_val', 'customdeploy1') + '&poId='+id;
        window.open(url, '_blank', 'width=500,height=500'); 
    } 
}

套房

function suitelet(request, response){
    if(request.getMethod() == 'GET') {
        var form = nlapiCreateForm('Add Item');
        form.addSubmitButton('Submit');

        var itemfield = form.addField('custpage_val', 'select', 'Item');
        var id = request.getParameter('id');

        var rec = nlapiLoadRecord('purchaseorder', id);
        var vend = rec.getFieldValue('entity');
        var search = nlapiSearchRecord(...search parameters...);

        for (result in search){
          if (search[result].getValue('vendor') == vend){
            itemfield.addSelectOption(search[result].id, nlapiLookupField('inventoryitem', search[result].id, 'itemid'));
          }
        }
        response.writePage(form);
    } else {
        var data = request.getParameter('custpage_item');
        response.write('<html><body><script>window.opener.addItemButtonCallback("'+data+'"); window.close();</script></body></html>');
    }
}

【问题讨论】:

    标签: javascript netsuite suitescript


    【解决方案1】:

    在客户端脚本上使用 nlapiGetFieldValue('entity') 并使用查询参数将其传递给 Suitelet,就像使用 poId 一样(如果这样做,您甚至可能根本不需要 poId + 无需加载记录在套件上)。

    另外,您可能希望通过运行一个搜索并传递一组 itemid 而不是为每个项目调用 nlapiLookupField 来优化您的代码。

    您可能需要修改 beforeLoad 以便在按下按钮时动态插入实体(我不记得 clientscript 按钮是否这样做)。像这样的:

    var suiteletURL = nlapiResolveURL('SUITELET', 'customscript_val', 'customdeploy1');
    var script = "var entity = nlapiGetFieldValue('entity'); var url = '" + suiteletURL + "'&entityId=' + entity;window.open(url, '_blank', 'width=500,height=500')";
    var button = form.addButton('custpage_addItemButton', 'Add Item', script);
    

    【讨论】:

    • 不敢相信我没有那样做!它工作得很好。它已经是动态的,所以我不必做太多修改。即使使用nlapiLookupField ,一切都很快,但我肯定会调查它。谢谢!
    猜你喜欢
    • 2014-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多