简体   繁体   中英

Suitescript 2.0: event.record.getCurrentSublistField is not a function

I am building a button on a work order using a user event script that will create an inventory adjustment using some of the information on a workorder and in a sublist. Button is created using a user event script and calls a client script.

I did some testing and when saving the inventory adjustment in the client script using non lot numbered items, it works and doesn't give me an error. When I try entering the inventory detail on lot numbered items, I get event.record.getCurrentSublistField is not a function. This error is not happening on my script but seems to be happening on a system script. I am adding my client script here. Any idea why this is happening?

define(['N/record', 'N/search','N/currentRecord','N/runtime'],

function(record, search, currentRecord,runtime) {

function pageInit(context) {

}

function buildSecondaryItems(){
    var currentWo = currentRecord.get();
    var currentId = currentWo.id;
    var account = runtime.getCurrentScript().getParameter('custscript_cab_accountparamater');
    console.log(currentId);
    console.log(account);

    var workOrder = record.load({
        type: "workorder", 
        id: currentId
    });

    var location = workOrder.getValue({
        fieldId: 'location'
    })
    var batch = workOrder.getValue({
        fieldId: 'custbody_cab_processingbatchfield'
    })
    var batchName = workOrder.getText({
        fieldId: 'custbody_cab_processingbatchfield'
    })

    var assembly = workOrder.getValue({
        fieldId: 'assemblyitem'
    })
    var subsidiary = workOrder.getValue({
        fieldId: 'subsidiary'
    })
    console.log("Location: "+location);
    console.log("Batch: "+batch);
    console.log("Batch Name: "+batchName);
    console.log("Assembly: "+ assembly);
    console.log("Subsidiary: "+ subsidiary);

    // Getting information from the related Assembly build on the Work order

    var assemblyBuildSearch = search.load({id: 'customsearch274'})
    var firstResult = runRelatedRecordSearch(assemblyBuildSearch,currentId)

    var glImpact = firstResult.getValue(assemblyBuildSearch.columns[1]);
    var qtyBuilt = firstResult.getValue(assemblyBuildSearch.columns[2]);
    var date = firstResult.getValue(assemblyBuildSearch.columns[3]);
    console.log("gl Impact: " + glImpact);
    console.log("qty Built: " + qtyBuilt);
    console.log("date: " + date);

    // Creating the Inventory Adjustment
    var inventoryAdjustment = record.create({
        type: "inventoryadjustment",
        isDynamic: true,
        defaultValues :null
    });
    // Setting Main value on Inventory Adjustment
    inventoryAdjustment.setValue({
        fieldId: 'subsidiary',
        value: subsidiary
    });
    inventoryAdjustment.setValue({
        fieldId: 'trandate',
        value: new Date(date)
    });
    inventoryAdjustment.setValue({
        fieldId: 'account',
        value: account
    });
    inventoryAdjustment.setValue({
        fieldId: 'adjlocation',
        value: location
    });

    inventoryAdjustment.setValue({
        fieldId :'custbody_cab_processingbatchfield',
        value: batch
    });
    inventoryAdjustment.setValue({
        fieldId :'custbody_cab_adjustmenttype',
        value: '2'
    });
    inventoryAdjustment.setValue({
        fieldId :'custbody_cab_invadjworkorder',
        value: currentId
    });


    //Entering the first line on the inventory Adjustment

    inventoryAdjustment.selectNewLine({
        sublistId: 'inventory'
    });
    inventoryAdjustment.setCurrentSublistValue({
        sublistId: 'inventory',
        fieldId: 'item',
        value: assembly
    });
    inventoryAdjustment.setCurrentSublistValue({
        sublistId: 'inventory',
        fieldId: 'location',
        value: location
    });
    inventoryAdjustment.setCurrentSublistValue({
        sublistId: 'inventory',
        fieldId: 'adjustqtyby',
        value: qtyBuilt
    });
    inventoryAdjustment.setCurrentSublistValue({
        sublistId: 'inventory',
        fieldId: 'unitcost',
        value: glImpact/qtyBuilt
    });


    //Selecting the inventory detail subrecord and setting the values.
    var subrecord = inventoryAdjustment.getCurrentSublistSubrecord({
        sublistId: 'inventory',
        fieldId: 'inventorydetail'
    });
    subrecord.selectNewLine({
        sublistId: 'inventoryassignment'
    });
    subrecord.setCurrentSublistValue({
        sublistId: 'inventoryassignment',
        fieldId: 'issueinventorynumber',
        value: "ALT1"
    });
    subrecord.setCurrentSublistValue({
        sublistId: 'inventoryassignment',
        fieldId: 'inventorystatus',
        value: '1'
    });
    subrecord.setCurrentSublistValue({
        sublistId: 'inventoryassignment',
        fieldId: 'quantity',
        value: qtyBuilt
    });


    // Committing the inventory detail and first line
    subrecord.commitLine({
        sublistId: 'inventoryassignment'
    });

    inventoryAdjustment.commitLine({
        sublistId: 'inventory'
    });



    var inventoryAdjustmentID = inventoryAdjustment.save({
        enableSourcing: true,
        ignoreMandatoryFields: false
    });


}



function runRelatedRecordSearch(assemblyBuildSearch,currentId){
    var filter = search.createFilter({              // Creates filter on created from field
        name:'createdfrom',
        operator: search.Operator.IS,
        values: currentId
    })
    assemblyBuildSearch.filters.push(filter);
    var results = assemblyBuildSearch.run();
    var firstResult = results.getRange({
          start: 0, 
          end: 1
        })[0];

    return firstResult;
}

return {
    pageInit: pageInit,
    buildSecondaryItems: buildSecondaryItems

};

});

Thank you in advance

Abed, I cannot comment too far, as I'm not familiar (I have never tried to script is this way), but client script that is called by a UE should be modular and is almost never deployed. - and hence therefore by design your call to 'custscript_cab_accountparamater' will necessarily fail.

UE's that call CS can pass parameters to CS by a similar (modified) process, and that is how CS is called with parameters. Perhaps that's what you should do.

But in my mind, first you'd need to change the structure of your client script that resembles a library - then you can then access the functions via the button, and hence further test..

I reached out to Netsuite support and the issue was cause by the "issueinventorynumber" fieldId. Even though that's the field on the record browser, the support rep confirmed that it's an error and an enhancement was open to change it. I need to use "receiptinventorynumber" for it to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM