This is my first time with scheduled scripts (I have only really done client side script prior to this), and I am having a difficult time figuring out what API calls I am supposed to be using.
I am also unsure how to go about testing a scheduled script.
To summarize, the script needs to look through all of today's sales orders, check the items in the order, and then check if any of the items have a certain value in a custom field. As soon as it finds an item with this value, it will set a custom boolean field on the sales order to true, save it, and move on to the next one.
Here's what I have so far. I have commented where I am unsure of what to do.
var DROPSHIP_ITEM_VALUE = 3; function isDropshipItem(itemId) { var ret = false; try { var record = nlapiLoadRecord('inventoryitem',itemId); var dsValue = record.getFieldValue('custitem_activeitem'); //name of the custom field on the item if( dsValue == DROPSHIP_ITEM_VALUE ) { ret = true; } } catch(e) { nlapiLogExecution('ERROR', ' (isDropShipItem) : ' + e.message); } return ret; } function orderHasDropshipItem(orderId) { var ret = false; try { var salesRecord = nlapiLoadRecord('salesorder', orderId); var itemCount = salesRecord.getLineItemCount('item'); for(var i = 1; i <= itemCount; i++) { //how do I retrieve each item in the sales order and then pass its internal id //to the isDropShip function? if( isDropshipItem(itemId) ){ ret = true; break; } } return ret; } catch(e) { nlapiLogExecution('ERROR', ' (orderHasDropshipItem) : ' + e.message); } } //not sure if any of this is right... function setDsOrderFlag(type) { var filters = new Array(); filters[0] = new nlobjSearchFilter( 'mainline', null, 'is', 'T' ); filters[1] = new nlobjSearchFilter( 'trandate', null, 'equalTo', 'today' ); var searchresults = nlapiSearchRecord( 'salesorder', null, filters, null, new nlobjSearchColumn('custitem_activeitem') ); for ( var i = 0; searchresults != null && i < searchresults.length; i++ ) { //how do I retrieve internal id of a sales order in this case? if( hasDropShipItem(orderId) ){ //how do I set a custom flag on the sales order to true and then save the record? } } }