Script to update 'Category' field on Risk Statement form

Venkataramudu A
Tera Contributor

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.

 

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('choice_category', gr.category);
    gr.addEncodedQuery("setINrisk_risk_def^name=infosec");
    choice.query();
    if (choice.next()) {      
        gr.category = choice;
        gr.update();
    }
}


1 ACCEPTED SOLUTION

@Venkataramudu A 

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.

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@Venkataramudu A 

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.

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

HI @Ankur Bawiskar 

 

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

VenkataramuduA_0-1734004613055.png

 

GRC Choice table:

VenkataramuduA_1-1734004656106.png

 

 

 

@Venkataramudu A 

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.

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

Thanks @Ankur Bawiskar 

 

By mistake i have updated incorrect variable on 6th line and i corrected after that it works.

 

Thank you