Reputation: 137
I have an AfterSubmit UserEventScript (support case) that correctly does the following:
Saves the newCustomer to the database
newCustomer.commitLine({
sublistId: 'addressbook'
});
newCustomer.save({
enableSourcing: true,
ignoreMandatoryFields: false
});
To my question, what are the next steps for replacing the old Customer with this newly created Customer on the support case? I've tried the following code, but it logs an "undefined" value.
recordSubmitted.setValue({
fieldId: "companyid",
value: newCustomer.companyId
});
Upvotes: 0
Views: 817
Reputation: 15367
The internal id of the new customer record is returned from the save function. The field you want to assign to has script id 'company'. So:
var custId = newCustomer.save({
enableSourcing: true,
ignoreMandatoryFields: false
});
recordSubmitted.setValue({
fieldId: 'company',
value: custId
});
Generally if you are choosing a different customer to assign the case to you should consider whether the different customer already exists so you might have loaded the other customer or found it via a search.
from a load and verify:
recordSubmitted.setValue({
fieldId: 'company',
value: differentCustomer.getValue({fieldId:'internalid'})
});
from a search you might get the id directly:
var custId = null;
mySearch.run().each(function(res){
if(test(res)){
custId = res.id;
return false;
}
return true;
});
if(custId) recordSubmitted.setValue({
fieldId: 'company',
value: custId
});
Upvotes: 2