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.

Background script

Manu143
Tera Contributor

Hi Community,

 How to write the fix script  to set the yes/no variable as yes for  the existing RITMS if the doallar amount value is greater  than or equal to 100000 .

 

Thanks,

Manu

7 REPLIES 7

Pratiksha
Mega Sage
Mega Sage

// Query the RITMS table
var ritms = new GlideRecord('table_name');
ritms.addQuery('amount', '>=', 100000); // Filter records with amount greater than or equal to $100,000
ritms.query();

// Update yes/no variable for qualifying records
while (ritms.next()) {
ritms.yes_no = 'yes';
ritms.update();
gs.info('Updated RITM ' + ritms.number + ': Yes/No set to yes');
}

_Gaurav
Kilo Sage

Hi @Manu143 
Below is the script that will update all the RITM variables to yes, just add the correct filter condition.

var grRITM  = new GlideRecord('sc_req_item');

grRITM.addQuery('' , '');// Please add the correct query condition here.

grRITM.query();

while(grRITM.next()){

grRITM.your_variable_backend_value = 'yes';

grRITN.update();

}

 

 

Always mark the fastest solution provided as helpful if that resolves your query.
Thanks!

Maddysunil
Kilo Sage

@Manu143 

You can write below script in fix script :

 

// Define the condition for updating RITMs
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addEncodedQuery('dollar_amount >= 100000'); // validate the field database name
ritmGr.query();
while (ritmGr.next()) {
    ritmGr.setValue('yes_no_variable', 'yes'); // validate yes_no_variable database name
    ritmGr.update();
}

gs.log("Fix script executed. Updated 'yes/no' variable for RITMs with dollar_amount >= 100000.");

 

Kindly mark helpful/accepted if it helps you.

Devang
Tera Contributor
var gr = new GlideRecord('sc_req_item');
gr.addQuery('amount >= 100000'); // considering the field name is amount
gr.query();
while (gr.next()) {
    gr.fieldname_of_dollar_field = 'yes';
    gr.update();
}