Trying to set expense line field values of Vendor ...
# suitescript
r
Trying to set expense line field values of Vendor Bill with value in the header (WF doesn't do this). Combining SA 80187 & 87622. But when I load the script file, I get: Syntax error: missing variable name. Here's the script:
// JavaScript Document
var search = nlapiLoadSearch('transaction', 'customsearch_nsts_vp_prepayments_on_ho_2') var res = search.runSearch() res.forEachResult(function(searchResult){ var = rec_id = searchResult.getValue('internalid') var bill = nlapiLoadRecord('vendorbill', rec_id); var totalCount = bill.getLineItemCount('item'); var project = nlapiLoadRecord('vendorbill', 'custbody_ref_proj_for_app.internalid'); for (var index = 1; index <= totalCount; ++index) { // Your intended update code for (var i=0; i < numLines ; i++) { // setting on line i the custom field value curRec.setSublistValue({ sublistId: 'expense', fieldId: '{job.internalid}', line: i, value: Project }); } } nlapiSubmitRecord(bill, false, true); return true })
b
Copy code
var = rec_id = searchResult.getValue('internalid')
this is the error causing line
later on you will get an error about an invalid internalid since
'custbody_ref_proj_for_app.internalid'
is not a valid internal id for a vendorbill
Copy code
var project = nlapiLoadRecord('vendorbill', 'custbody_ref_proj_for_app.internalid')
you have written a unnecessary and error causing nested loops
you should only have 1 loop, that goes from index 1 upto and including the totalCount
s
Untitled
b
it should look like
Copy code
for (var i = 1; i <= totalCount; ++i) {
s
the sad thing about loops is they don't express intent.
forEach
expresses intent with a well known name and semantics.
if I'm not mistaken, the two lines I show above is the entire ask (albeit using NFT)
b
im not really sure which field you are trying to set with which value with
Copy code
curRec.setSublistValue({
  sublistId: "expense",
  fieldId: "{job.internalid}",
  line: i,
  value: Project,
});
but the field internal id is incorrect, and there is no variable named Project
r
Sorry, just saw your comments, thanks for all, will look into this further