How to dynamically add a record type?
Answered
When dynamically adding record type I get the following error:
The record type [RECORD.TYPE.WORK_ORDER_ISSUE] is invalid.
Here is the function:
async function transform(recObj){
try{
let curRecord = await record.transform.promise({
fromType: recObj.fromType,
fromId: recObj.fromId,
toType: recObj.toType,
//toType: record.Type.WORK_ORDER_ISSUE,
isDynamic: false
})
log.debug(‘157’, curRecord);
await curRecord.save.promise();
return curRecord;
}
if I replace
fromType: recObj.fromType,
toType: recObj.toType,
with fromType: record.Type.WORK_ORDER,
toType: record.Type.WORK_ORDER_ISSUE,
if works fine without errors.
values for :
fromType is record.Type.WORK_ORDER a string
toType is record.Type.WORK_ORDER_ISSUE a string
Best answer
Hi,
So is the string ‘record.Type.WORK_ORDER’?
If so, that will not work. Are you not able to pass record.Type.WORK_ORDER directly to the function?
Failing this, since these are enumerations, you can just use the string they represent, i.e. ‘workorder’.
Thanks,
Chris
You got me on the right track. Since it is an enum it can not be addressed with a sting (What throws me though is that it works sometimes).
I modified my code as follows:
let curRecord = await record.load.promise({
type: record.Type[recordObj.recordType],
id: recordObj.recordId,
isDynamic: true
});
It appears to be working now.
Thank you very much
I am not able to pass record.Type.WORK_ORDER directly to the function because I am passing from and external source to the suitelet.
I did not try your suggestion of passing the string they represent, i.e. ‘workorder’. But I am sure that would work also. I will keep the suggestion for future reference.
Thanks again
Brilliant – I’m really pleased you got it working.



