How to dynamically add a record type?

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
Rookie Asked on March 21, 2024 in SuiteScript.
Add Comment
2 Answer(s)
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

Advanced Answered on March 22, 2024.
Add Comment

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
Rookie Answered on March 22, 2024.

Brilliant – I’m really pleased you got it working.

on March 22, 2024.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   SuiteMigration   Become a Sponsor