This topic contains 5 replies, has 0 voices, and was last updated by Brad_PHX 8 years, 3 months ago.

  • Author
    Posts
  • #6290

    Brad_PHX

    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 This is a cached copy. Click here to see the original post.

  • #6291

    JayDP123

    I saw this in the afterSubmit documentation:

    “1. Load the record you want to make changes to by calling the nlapiLoadRecord API. Do NOT load the record object by using nlapiGetRecord, as this API returns the record in READ ONLY mode; therefore, changes made to the record cannot be accepted and an error is thrown. 2. After using nlapiLoadRecord to load the record, make the changes to the record, and submit the record.”

    I noticed you were using nlapiGetRecord. Have you tried nlapiLoadRecord instead ?

  • #6292

    david.smith

    Just guessing here…

    Code:
    var poid = nlapiGetFieldValue(‘createdfrom’);
    if(!poid) return;
    var poSearch = nlapiSearchRecord(‘purchaseorder’,null,[[‘internalid’,’is’,poid],’and’,[‘mainline’,’is’,’T’]],[new nlobjSearchColumn(‘internalid’,’requestor’)]) || [];
    if(poSearch.length)
    nlapiSetFieldValue(‘nextapprover’,poSearch[0].getValue(‘internalid’,’requestor’));

  • #6293

    khultquist

    My guess is that you are not using aftersubmit, but actually using beforesubmit. In order to use aftersubmit, you would need to reload the record, change the value of nextapprover, then submit again.

    Here’s some suggested code (untested)

    Code:
    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 recordType = nlapiGetRecordType();
    var record = nlapiLoadRecord(recordType, vendorBillID);

    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]);

    record.setFieldValue('nextapprover', vEmpIntID);
    var id = nlapiSubmitRecord(record, true);

    }
    }
    }
    }

  • #6294

    Bednar

    Our answer to that was to create a inline/hidden field called ‘Vendor Bill Approver’ on Purchase Transactions and use UE scripts to capture that on the POs. When you transform the record/receive the PO/bill the PO, that carries forward to the VB, no additional work needed.

  • #6295

    Brad_PHX

    Thanks everyone for your input. It is very appreciated. We’ll take your suggestions and give it another go.

You must be logged in to reply to this topic.