ah so just delete the like number 5
# suitescript
j
ah so just delete the like number 5
n
Hi Jamie
j
Hi
n
I have a question, if you can help
This was asked in one of the knowledge test. I am still looking for the answer. its short , can you help
j
I'll try, ask away
n
What do you see wrong, or what would you change, or consider changing, in the following code function? CLIENT SIDE SCRIPT RUNNING ON SALES ORDERS TRIGGER: FIELD CHANGE function fieldChange_setSalesRepSector(sublist, name){ if (sublist == 'item' && name == 'item') { var filters = []; filters.push(new nlobjSearchFilter('custentity_item', null, 'is', nlapiGetCurrentLineItemText('item', 'item'))); columns = []; columns.push(new nlobjSearchColumn('internalid')) var results = nlapiSearchRecord('employee', null, filters, columns); nlapiSetCurrentLineItemValue('item', 'custcol_rep_responsible', results[0].getValue('internalid'));
I can think of 2 things: #1: Var is missing in columns array declaration #2: nlapiGetCurrentLineItemText can return multiple results , so nlapiGetCurrentLineItemValue shoudl be used
j
Yeah I was going to mention using getCurrentLineItemValue instead of Text. Also you might want to check if results has anything before using a value from it. For example
Copy code
var results = nlapiSearchRecord('employee', null, filters, columns);

if(results.length > 0){
    nlapiSetCurrentLineItemValue('item', 'custcol_rep_responsible', results[0].getValue('internalid'));
}
n
is there any issue in these lines function fieldChange_setSalesRepSector(sublist, name){ if (sublist == 'item' && name == 'item') { var filters = [];
j
you could have the linenum variable in the function like
function fieldChange_setSalesRepSector(sublist, name, linenum)
n
if (sublist == 'item' && name == 'item') What this is checking in this line ?
j
It is checking that the sublist that has been edited was the item sublist and checking that the field on that sublist that was changed was the item field.
n
ok. Thank you very much , you have been helpful
one last concern , are we unnecessorily searching employee ? is that internalid already available at that point without performing search ?
j
You are welcome.
Without seeing the record I wouldn't be able to know, there is nothing in the code that suggests it is already available.
n
ok . Thanks a lot
j
This would however be possible to achieve with added sourcing on the field so that the value was pulled in when the item was added.
n
yeah, thats true. Even the value can be loaded in hidden field while the load performed , and then it can be used here without performing search
but this code doesnt suggest that requirement