简体   繁体   中英

Verify State in Script before Adding Line item (NetSuite)

I am trying to add a line to a Sales Oder when a specific item has been added, but before it does, I need it to verify the state first.

This is where my struggle comes in. I have the code to add the item correctly working, but my state check errors out.

 function validateField(type, name, linenumber) { var shipstate = nlapiGetFieldText() if (shipstate == 'PA') { function recalc(type) { if (type == 'item') { var itemId = nlapiGetCurrentLineItemValue('item', 'item'); if (itemId == 1658) { //Insert item nlapiSelectNewLineItem('item'); nlapiSetCurrentLineItemValue('item', 'item', 1516); nlapiSetCurrentLineItemValue('item', 'quantity', 1); nlapiSetCurrentLineItemValue('item', 'amount', '0.24'); nlapiCommitLineItem('item'); } } return true; } } return true; } 

Any insight to where my issue is?
I think my issue is where I'm storing the state value so it can check the variable.

I would recommend adding your line with a recalc function instead of a validateField function. This is because if you try to add a new line while you are still editing an existing line it will cancel out of your current line. With a recalc function it will wait until you hit the 'Add' button on the existing line before checking the state and adding a new line.

You are on the right track with your state validation, the function you need is nlapiGetFieldValue('shipstate'); . I believe the code below should solve your issue.

function recalc(type) {
    var shipstate = nlapiGetFieldValue('shipstate');
    if (shipstate === 'PA') {
        addNewLine(type);
    }
    return true;
}

function addNewLine(type) {
    if (type === 'item') {
        var itemId = nlapiGetCurrentLineItemValue('item', 'item');
        if (itemId === '1658') {
            //Insert item
            nlapiSelectNewLineItem('item');
            nlapiSetCurrentLineItemValue('item', 'item', '1516');
            nlapiSetCurrentLineItemValue('item', 'quantity', '1');
            nlapiSetCurrentLineItemValue('item', 'amount', '0.24');
            nlapiCommitLineItem('item');
        }
    }
    return true;
}

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