Get the sys_id of the target record to set to the variable of record producer

k_47
Tera Contributor

Hi,

 

I want to set the sys_id of the target record to the variable of record producer.

I've seen other community articles that say this is difficult, so I asked if it was updated with the latest information.

In case it is still difficult, I will write what I want to achieve below, so if you have any advice on other methods, I would like to hear it.

 

The requirement is that the URL that transitions to the same record on the platform screen is displayed in Link format on the screen of the request record of the custom table on the Employee center.

 

Thank you in advance.

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@k_47 

I don't think you can get the sysId of the target record when record producer opens up.

Why not store that in a hidden variable and set it via record producer script or after insert BR script?

Didn't get your business requirement completely. please share some screenshots.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

yuvarajkate
Giga Guru

To set the sys_id of the target record to a variable in a Record Producer, it's not as difficult as some articles may suggest, but it does require proper handling of the relationship between the Record Producer, target record, and the platform screen.

Steps to achieve your requirement:

  1. Use a Script in the Record Producer: You can use a Script in the Record Producer to set the sys_id of the target record and then generate the URL dynamically.

  2. Create a Variable for the URL: Add a variable in the Record Producer where you want to display the link. In the script, set this variable with the URL of the target record.

  3. Generate the URL in the Script: You can use the GlideRecord API to fetch the target record and construct the URL. 
    Script:

 

(function() {
    var targetRecord = new GlideRecord('custom_table');  
    if (targetRecord.get(current.target_record_sys_id)) { 
        var recordURL = targetRecord.getLink();
        producer.target_record_url = recordURL; 
    }
})(current, producer);

 

k_47
Tera Contributor

Thank you for replying.


I confirmed in the log that I was successfully able to obtain the URL.
However, when I completed the application, the following error was displayed on the completion screen, and no value was entered in the URL variable.
Do you know any way to solve this?


ErrorAccess to api 'put(sys_user.XXX)' from scope 'YYY' has been refused due to the api's cross-scope access policy.

 

XXX is the URL variable on the record producer.
YYY is the scope containing the record producer.

 

Thank you in advance.

Ankur Bawiskar
Tera Patron
Tera Patron

@k_47 

I don't think you can get the sysId of the target record when record producer opens up.

Why not store that in a hidden variable and set it via record producer script or after insert BR script?

Didn't get your business requirement completely. please share some screenshots.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader