Need to run the query between specific date range

Lusifer1984
Tera Contributor

HI,

The below is my query for a table to update record via fix script or background script.

 

var gr = new GlideRecord('fm_expense_line');
gr.query();
while(gr.next())
{
var currentDesc = gr.getValue('short_description');
gr.setValue('short_description',currentDesc+' ');
gr.update();
gr.setForceUpdate('true');
}

 

now since in the table number of record is more then  100K hence I want to run the query for specific date range like then How I can add the same in the code.

find_real_file.png

1 ACCEPTED SOLUTION

Filipe Cruz
Kilo Sage
Kilo Sage

Hello ARNAB,


Do you want to know a secret? 🙂
If you are able to filter that data in the list view, then this is piece of cake!!

Check this example here: I will filter in the incident table, active records with status New and In Progress:
find_real_file.png

Then, on top, I will see the filter query:

find_real_file.png

Now, if I right click on the end of the filter query (in my case the "state in (New, In Progress)"), I will see three options:
find_real_file.png

From there, you select "Copy query".

Then, go to your script and use the addEncodedQuery method

var gr = new GlideRecord('fm_expense_line');
gr.addEncodedQuery(<PASTE_YOUR_QUERY_HERE>);
gr.query();
while(gr.next())
{
var currentDesc = gr.getValue('short_description');
gr.setValue('short_description',currentDesc+' ');
gr.update();
gr.setForceUpdate('true');
}

 

Hope this helps!!

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

View solution in original post

1 REPLY 1

Filipe Cruz
Kilo Sage
Kilo Sage

Hello ARNAB,


Do you want to know a secret? 🙂
If you are able to filter that data in the list view, then this is piece of cake!!

Check this example here: I will filter in the incident table, active records with status New and In Progress:
find_real_file.png

Then, on top, I will see the filter query:

find_real_file.png

Now, if I right click on the end of the filter query (in my case the "state in (New, In Progress)"), I will see three options:
find_real_file.png

From there, you select "Copy query".

Then, go to your script and use the addEncodedQuery method

var gr = new GlideRecord('fm_expense_line');
gr.addEncodedQuery(<PASTE_YOUR_QUERY_HERE>);
gr.query();
while(gr.next())
{
var currentDesc = gr.getValue('short_description');
gr.setValue('short_description',currentDesc+' ');
gr.update();
gr.setForceUpdate('true');
}

 

Hope this helps!!

Please mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz