- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 03:11 AM
Hello Everyone,
I am trying to update 'category' dropdown field referring from GRC choice table. but the value is not updating using below script.
Can someone help on this please.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 04:11 AM
the category field on "sn_risk_definition" table refers to "sn_grc_choice" table and holds sysId
what's your business requirement here?
if you want to update the category on Risk Statement with GRC Choice as Credit then use this
var gr = new GlideRecord('sn_risk_definition');
gr.addEncodedQuery("nameSTARTSWITHTraining and Development");
gr.query();
while (gr.next()) {
var choice = new GlideRecord('sn_grc_choice');
gr.addEncodedQuery("setINrisk_risk_def^name=Credit");
choice.query();
if (choice.next()) {
gr.category = choice.getUniqueValue();
gr.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 03:23 AM
try this
var gr = new GlideRecord('sn_risk_definition');
gr.addEncodedQuery("nameSTARTSWITHTest category");
gr.query();
while (gr.next()) {
var choice = new GlideRecord('sn_grc_choice');
choice.addQuery('sys_id', gr.category); // query here with sys_id
gr.addEncodedQuery("setINrisk_risk_def^name=infosec");
choice.query();
if (choice.next()) {
gr.category = choice.getUniqueValue(); // set the choice sysId in category field
gr.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 03:59 AM
Thanks for the reply.
I have used your code to update category field on risk statement form but its not working.
Below are choices available in GRC table. Suppose if i want to update on 'Credit' value on risk statement. can you help on this
GRC Choice table:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 04:11 AM
the category field on "sn_risk_definition" table refers to "sn_grc_choice" table and holds sysId
what's your business requirement here?
if you want to update the category on Risk Statement with GRC Choice as Credit then use this
var gr = new GlideRecord('sn_risk_definition');
gr.addEncodedQuery("nameSTARTSWITHTraining and Development");
gr.query();
while (gr.next()) {
var choice = new GlideRecord('sn_grc_choice');
gr.addEncodedQuery("setINrisk_risk_def^name=Credit");
choice.query();
if (choice.next()) {
gr.category = choice.getUniqueValue();
gr.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2024 04:24 AM
Thanks @Ankur Bawiskar
By mistake i have updated incorrect variable on 6th line and i corrected after that it works.
Thank you