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

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.

Then just the other way around. Instead of current.etc, just user:

gr_rec.your_reference_field = current.getUniqueValue();

You can add this within your gr_rec, so before the .insert();

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 Shaik,

as suggested by Mark please use current.getUniqueValue() to set the reference field

Note: one issue with this would be consider some before insert BR blocks the insert; still there will be orphan records in u_talent_management table;

So I would suggest to use after insert BR on incident table

updated script below

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.u_incident = current.getUniqueValue(); // use proper field name here
gr_rec.insert();
}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

I tried with after BR initially Ankur but the problem is i am not getting the MRVS json data i am undefined in the logs 

Hi Shaik,

to access variables on incident BR you need to use this

var mrvs = current.variables.goal;

then continue parsing and creating records

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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