How to populate a reference field via script.

ZacharyW
Tera Expert

Hello All,

I have a catalog item workflow that creates a standard change using a script. This catalog item also has a reference variable pointed at the change table. I would like to update this value to reference the change I created from this script, but am completely lost on how to do it.

I think there is a fundamental issue with my approach. I don't need a specific fix, but from a high level view, what is the best way to accomplish this?

 

Thanks in advance for the advice!

1 ACCEPTED SOLUTION

HarshTimes
Tera Guru

When you are creating change record, get the sysId of the record as below

var chgSysId  = chgObj.insert(); // chgSysId   will contain the sysId of new record created

Now add this to the variable as below.

current.variables.NAME_OF_VARIABLE =  chgSysId   ;

current.update(); 

View solution in original post

3 REPLIES 3

Alok Das
Tera Guru

Hi,

It would have been easy for us to directly help you with the script if you would have posted the one which you are referring to, however In reference field you can update the sys_id of the created change.

Kindly mark my answer as Correct and helpful based on the Impact.

Regards,

Alok

DrewW
Mega Sage
Mega Sage

To update a reference field you need to use the method setValue and the sys_id of the record or use the method setDisplayValue and then the text display value of the record.  sys_id's are probably the better way but it depends on what you are doing and the data you have on hand at the time.

 

HarshTimes
Tera Guru

When you are creating change record, get the sysId of the record as below

var chgSysId  = chgObj.insert(); // chgSysId   will contain the sysId of new record created

Now add this to the variable as below.

current.variables.NAME_OF_VARIABLE =  chgSysId   ;

current.update();