Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get the sys id of the target table in the producer script in RP

shaik_irfan
Tera Guru

Hi,

 

On the record producer script i have a script written to insert a new record in custom table which is working fine. Now the record producer is creted on incident table i want to relate the record which i am creating via script is for associate incident, so how can i get the sys id or the incident number for the target record in the producer script ?

1 ACCEPTED SOLUTION

Hi Irfan,

 

Can you add something as below before your gr_rec.insert();

gr_rec.(yourreferencefieldname)=current.sys_id;

 

I did try it in my PDI & it works as sys_id for the record is generated before other updates so the above works.

View solution in original post

10 REPLIES 10

Mark Roethof
Tera Patron
Tera Patron

Hi there,

So you're adding the record on your custom table through the Record Producer script? For example by using a GlideRecord query?

After the insert, you could actually just use gr.getUniqueValue (assuming you're naming for the GlideRecord is gr). So within the same Record Producer script, you could update the Incident.

For example:

current.your_reference_field = gr.getUniqueValue(); 

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi Mark,

 

I have a RP which is on incident table, now when ever user raise a request it creates a record in Incident Table.

 

On the RP script i have a script to insert a record in custom table which is u_talent_management

 

below is the script:

var mrvs = producer.goal;
rowCount = mrvs.getRowCount();
for (var i = 0; i < rowCount; i++){
var row = mrvs.getRow(i);
// If Request Exists, Force Update Instead
var gr_rec = new GlideRecord("u_talent_management") ;
gr_rec.initialize();
gr_rec.u_goal1 = row.goal1;
gr_rec.u_goal2 = row.goal2;
gr_rec.u_quarter = row.quarter;
// Insert Record
gr_rec.insert();
}

 

Now on the u_talent_management table i have a reference field that referring to incident table where i want to set the incident number which was created by the user 

 

Ex: Incident created with Number: INC000021

 

i want to set the  INC000021 number in the u_talent_management record which i am creaing via RP script

 

 

Hi,

why not have after insert BR on incident table for this?

Regards
Ankur

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

Hi i also facing same issue 

i have custom table and a ui action button on that table form, that button redirect me to a record producer.

in that record producer i have a variable 'comment' if user fill it and submit i need to set value of a choice field on my custom table form. 

but whenever the user submit the RP it  sets the choice field value  on a new record, not on the record that i went to the RP.

How to solve this issue