Hi Guys,
I am trying to, upon saving a vendor bill, locate the PO from which it was created, capture the "employee", and populate that individual as my next approver on my unapproved vendor bill. Below is what we are currently trying, and what we find is that it works successfully after adding the "edit" type parameter, and then editing and saving the already existing vendor bill, however, upon save during creation, the next approver field is not being successfully set. I think this is because the record (vendor bill) has not been written to the database by the time my search is run? Even though my script should be triggered after submit? If this cannot work, might someone here have a suggestion on how i may solve through alternate means? The script seems like it should not be at all necessary, but the lack of natural join on screen from the vendor bill to its PO makes this more challenging.
Any help would be tremendously appreciated!
Thanks in advance.
function setNextApprover(type){
if (type == 'create' || type == 'edit' ){
var vendorBillID = nlapiGetRecordId();
var searchFilters = new Array();
searchFilters[0] = new nlobjSearchFilter('type', null, 'anyof', 'VendBill');
searchFilters[1] = new nlobjSearchFilter('mainline', null, 'is', 'true');
searchFilters[2] = new nlobjSearchFilter('internalidnumber', null, 'equalto', vendorBillID);
var searchColumns = new Array();
searchColumns[0] = new nlobjSearchColumn('internalid');
searchColumns[1] = new nlobjSearchColumn('createdfrom');
var results = nlapiSearchRecord('transaction',null , searchFilters, searchColumns);
for (var i = 0; results != null && i < results.length; i++){
var searchResults = results[i];
var vcreatedFrom = results[i].getValue(searchColumns[1]);
If (vcreatedFrom != null){
var POsearchFilters = new Array();
POsearchFilters[0] = new nlobjSearchFilter('internalidnumber',null,'equalto',vcreatedFrom);
POsearchFilters[1] = new nlobjSearchFilter('mainline',null,'is',true);
POSearchColumns = new Array();
POSearchColumns[0] = new nlobjSearchColumn('internalid','requestor');
var POSearchResult = nlapiSearchRecord('purchaseorder',null,POsearchFilters, POSearchColumns);
var vEmpIntID = POSearchResult[0].getValue(POSearchColumns[0]);
nlapiSetFieldValue('nextapprover',vEmpIntID);
}
}
}
}
Thanks again for any assistance you can provide!
Regards,
Brad