How to pass the value from system property to Fix script

Community Alums
Not applicable

Hi All,

 

I have written a fix script to close the request and RITM that were 90 days old. I have written a system property to store the value 90 with type as string and calling the property in encoded query of Opened 90 days ago.

But the script is not working as expected it is closing all the RITM and Request.

 

var prop = gs.getProperty('old_req');

gs.print(prop);

var gr = new GlideRecord('sc_request');

gr.addEncodedQuery('opened_at<javascript&colon;gs.daysAgo("prop")^active!=false');

gr.query();

while(gr.next()){

    var gr_req_item = new GlideRecord('sc_req_item');

    gr_req_item.addQuery('request',gr.sys_id);

    gr_req_item.query();

    if(gr_req_item.next()){

        gr_req_item.state = '3';

        gr_req_item.stage = 'complete';

        //gr_req_item.setWorkflow(false);

        gr_req_item.update();

    }

    gr.state = '3';

    gr.update();

}

 

Anyone can help me on this 

3 REPLIES 3

Vaibhav127
Tera Guru

Hi @Community Alums ,

In your script in line

gr.addEncodedQuery('opened_at<javascript&colon;gs.daysAgo("prop")^active!=false');

make this change

gr.addEncodedQuery('opened_at<javascript&colon;gs.daysAgo(parseInt(prop))^active!=false');

Stefan Georgiev
Tera Guru

Hello @Community Alums ,

maybe you should try to change the IF with WHILE, because requests can have more than one RITM and all need to be closed before the REQ gets closed. YOu should consider closing the sc_tasks as well. 
Hope that this helps you!

If the provided information answers your question, please consider marking it as Helpful and Accepting the Solution so other community users can find it faster.

All the Best,
Stefan

SunilKumar_P
Giga Sage

Hi @Community Alums , Please test the below script.

 

var prop = gs.getProperty('old_req');
var propAsNumber = parseInt(prop); // Change it to an Integer
var gr = new GlideRecord('sc_request');
gr.addEncodedQuery('opened_at<javascript&colon;gs.daysAgo(propAsNumber)^active!=false');
gr.query();
if (gr.next()) { // You need to change the if to while to loop through the records.
    var gr_req_item = new GlideRecord('sc_req_item');
    gr_req_item.addQuery('request', gr.sys_id);
    gr_req_item.query();
    if (gr_req_item.next()) {
        gr_req_item.state = '3';
        gr_req_item.stage = 'complete';
        //gr_req_item.setWorkflow(false);
        gr_req_item.update();
    }
    gr.state = '3';
    gr.update();

}
 
Regards,
Sunil