Reputation: 65
I cored a saved search, and when I logdebug the results appear as I want. but when I try to set the value to the destination field, there is no response with any results.
if(cust){
var custSave = search.create({
type: "customrecord_me_customer_sales_person",
filters:
[
["custrecord_me_customer_name","is",cust],
],
columns:
[
search.createColumn({name: "custrecord_me_customer_name", label: "ME - Customer Name"}),
search.createColumn({
name: "custrecord_me_join_sales_person",
sort: search.Sort.ASC,
label: "ME - Join Customer Sales Person"
})
]
});
log.debug(
"sales person"+JSON.stringify(custSave)
);
var custSR = custSave.run().getRange(0, 1000);
var cust = custSR[0].getText("custrecord_me_join_sales_person");//the result I want in
log.debug(
"join customer sales person"+JSON.stringify(cust)
);
return true;
if (cust.hasOwnProperty('custrecord_me_join_sales_person')){
var salesPerson = cust.getValue('custrecord_me_join_sales_person')[0].value;
//var salesPerson = currentRecord.getValue({"custrecord_me_join_sales_person"});
currentRecord.setValue({ fieldId: 'custbody_me_field_deposit_salesman', value: salesPerson });
}
else{
currentRecord.setValue({ fieldId: 'custbody_me_field_deposit_salesman', value: null });
}
}
}
}
return {
fieldChanged: fieldChanged
}
is there an error in my script (there is no error notification). thanks for answering
Upvotes: 1
Views: 173
Reputation: 1063
Your code is so badly indented that you can't read it properly, so you didn't see you exit your code before setting the value. Here a version of your code somewhat indented:
if (cust) {
var custSave = search.create({
type: "customrecord_me_customer_sales_person",
filters: [
["custrecord_me_customer_name","is", cust],
],
columns: [
search.createColumn({name: "custrecord_me_customer_name", label: "ME - Customer Name"}),
search.createColumn({
name: "custrecord_me_join_sales_person",
sort: search.Sort.ASC,
label: "ME - Join Customer Sales Person"
})
]
});
log.debug("sales person" + JSON.stringify(custSave));
var custSR = custSave.run().getRange(0, 1000);
//the result I want in
var cust = custSR[0].getText("custrecord_me_join_sales_person");
log.debug("join customer sales person"+JSON.stringify(cust));
return true; /////////// HERE
if (cust.hasOwnProperty('custrecord_me_join_sales_person')) {
var salesPerson = cust.getValue('custrecord_me_join_sales_person')[0].value;
//var salesPerson = currentRecord.getValue({"custrecord_me_join_sales_person"});
currentRecord.setValue({
fieldId: 'custbody_me_field_deposit_salesman',
value: salesPerson
});
} else {
currentRecord.setValue({
fieldId: 'custbody_me_field_deposit_salesman',
value: null
});
}
}
}
}
return { fieldChanged: fieldChanged }
}
seems to persist, you may have not properly copy / pasted your codereturn true
(exiting gracefuly without any errors or logs, like you told) before having the opportunity to perform your currentRecord.setValue()
Upvotes: 0