Saturday, February 9, 2019

Carry over the set PO Vendor from the original Sales Order when using Make Copy

DISCLAIMER: This requires knowledge in SuiteScript.

There are instances when users would like to copy Sales Order transactions where the PO Vendor set on the items is not that of those items' preferred PO vendors.

When using Make Copy, the PO vendor is not being automatically copied from the original sales order rather it is being sourced based on the item indicated on the order. Thus, it is the preferred PO vendor of the item which is being set, by default, rather than that of the PO vendor set on the original Sales Order.

Below is a sample client side script, triggered on Page Init, which could be used to meet such use case.


function setPOVendor(type) {

if (type == 'copy'){

nlapiLogExecution('DEBUG','enter', 'yes');

var origID= getOrigID('id');
nlapiLogExecution('DEBUG','origID', origID);

var cnt= nlapiGetLineItemCount('item');
nlapiLogExecution('DEBUG','cnt', cnt);

var rec= nlapiLoadRecord('salesorder',origID);

for(var i=1; i<=cnt; i++)
{

var origVendor = rec.getLineItemValue('item','povendor',i);
nlapiLogExecution('DEBUG','origVendor '+i, origVendor );

nlapiSelectLineItem('item',i);
nlapiSetCurrentLineItemValue('item','povendor',origVendor,'true','true');
nlapiCommitLineItem('item');

}

}

}

function getOrigID( name ){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
var regexS = "[\\?&]"+name+"=([^&#]*)";  
var regex = new RegExp( regexS );  
var results = regex.exec( window.location.href );
 if( results == null )    return "";  
else    return results[1];

}

No comments:

Post a Comment