'Suitescript 2.0 record.load either Lead or Prospect
I created a user event script that updates a lead custom field from a new phone call record on afterSubmit. It loads the customer from the id of the entity id on the phone call event. It works fine, but it loads a lead record only. How do I fine tune this script to get the entity type and then use that to determine which record type to load?
function afterSubmit(context) {
var phoneRec = context.newRecord;
var checkbox1 = phoneRec.getValue({
fieldId: 'custevent_field1'
});
var checkbox2 = phoneRec.getValue({
fieldId: 'custevent_field2'
});
var custId = phoneRec.getValue({
fieldId: 'company'
});
if(custId && checkbox1 == true) {
var loadedcust = record.load({
type : record.Type.LEAD,
id : custId});
loadedcust.setValue({
fieldId:'custentity_filed1',
value: true });
loadedcust.save();
}
if(custId && checkbox2 == true) {
var loadedcust = record.load({
type : record.Type.LEAD,
id : custId});
loadedcust.setValue({
fieldId:'custentity_field2',
value: true });
loadedcust.save();
}
}
return {afterSubmit}
Not sure how to pull more entity information from just the id value. Any insight will help.
Solution 1:[1]
Yes you should be able to use just customer.
Also unless your values are exclusive you can also do the following to make the return quicker:
define(['N/record',...], function(record,...){ // include record module in your define
function afterSubmit(context) {
var phoneRec = context.newRecord;
var checkbox1 = phoneRec.getValue({
fieldId: 'custevent_field1'
});
var checkbox2 = phoneRec.getValue({
fieldId: 'custevent_field2'
});
var custId = phoneRec.getValue({
fieldId: 'company'
});
var updates = {};
var anyUpdate = false;
if(custId && checkbox1 == true) {
updates.custentity_filed1 = true; //not field1?
anyUpdate = true;
}
if(custId && checkbox2 == true) {
updates.custentity_field2 = true;
anyUpdate = true;
}
if(anyUpdate){ //single update. No need to load record twice nor submit it twice.
record.submitFields({
type:'customer',
id:custId,
values:updates
})
}
}
return {afterSubmit}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bknights |
