Hi,
I have developed this script by copying another one. Translating this into English makes sense and should work but it doesn't.
I have created a test order with two items - An Early Bird item and a non early bird item. The script keeps flagging the field with 'Ok to Fully Fulfill' even though there is an early bird item.
What I want it to do :
[LIST]
[*]I want the script to loop through all the items on the sales order.
[*]Find any items which is ticked as Early Bird on the Item Page
[*]If there are Early Bird Items I want the field to be flagged as 'Contains an Early Bird'
otherwise to flag the field as 'Ok to Fully Fulfill'.
[/LIST]
Please can someone have a look
Thanks
The Script
function SetFieldValue(type, edit) { // The itemDetails search can be done in an after submit phase when you are sure the order has an id. var itemDetails = nlapiSearchRecord('salesorder', null, new nlobjSearchFilter('internalid', null, 'is', nlapiGetRecordId()), [ new nlobjSearchColumn('custitem_ebird_pre_order', 'item'), new nlobjSearchColumn('item') ]); // 1. hasEarlyBird to detect if there is a Early Bird item var hasEarlyBird = false if(itemDetails != null) { // 2. Loop through all items in the sales order. for(var i = 0; i < itemDetails.length; i++) { if(itemDetails[i].getValue('custitem_ebird_pre_order', 'item') == 'T') { // If the line item is a Early Bird item, mark hasEarlyBird as true. hasEarlyBird = true; } else if(itemDetails[i].getValue('custitem_ebird_pre_order', 'item') == 'F') { // If the line item is not an Early Bird item, mark hasEarlyBird as false. hasEarlyBird = false; } } } // 3. If Early Bird is true, then set field value. if(hasEarlyBird == true) { nlapiSubmitField('salesorder', nlapiGetRecordId(), 'custbody_eb', 'Contains an Early Bird'); } else if(hasEarlyBird == false) { nlapiSubmitField('salesorder', nlapiGetRecordId(), 'custbody_eb', 'OK to Fully fullfil'); } }