- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 04:01 AM
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 ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 04:31 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 04:31 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 04:46 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:00 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:06 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-19-2020 05:15 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
