
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2017 03:45 PM
Hi ServiceNow Community,
I've this problem and I hope someone can help me:
I've this table [u_history_task] and I've need to run a job that calcolate for each record value of columns "u_order" and "u_last".
This is a screen of table with an example of records before and How it should be after run the job:
thanks,
Best Regards.
Davide.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2017 06:27 AM
Ahh... Now that I after a while look at your pictures I think I get what you after.. sometimes you just stares blind on something 😃
Something like this and it only does 2 server calls.
var count = 1; //Get the counter read
var gr = new GlideRecord('change_task'); //Fetch the records we want to update
gr.orderBy('NAME OF YOUR TASK FIELD');
gr.orderBy('sys_updated_on');
gr.query();
var gr2 = new GlideRecord('change_task'); //Fetch another set of record so we can compare to the "next" record
gr2.orderBy('NAME OF YOUR TASK FIELD');
gr2.orderBy('sys_updated_on');
gr2.query();
gr2.next();//Skip ahead one record so gr2 always is one record ahead of gr
while(gr.next()){
if(!gr2.next()){//If there isn't a next record in gr2, gr is the last one
gr.setValue('u_last',true);//To handle the last record
}
gr.setValue('u_order',count);
//Check if the is is the last one and reset the counter if that is true.
if (gr.getValue('NAME OF YOUR TASK FIELD') != gr2.getValue('NAME OF YOUR TASK FIELD')){
gr.setValue('u_last',true);
count = 1;
}
//If it isn't the last one, add 1 to the counter
else {
count++;
}
gr.autoSysFields(false); //Guess you don't want the sys_updated_on field to be updated when you run your script.
gr.update();
}
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2017 04:16 PM
Thank you so much Goran for your perspective. Yes, I do agree that for all the existing records, it should be a one time fix and for the new records it has to be a BR. I'm personally a bit hesitant to do a bulk edit unless and until, that's the option left for me.
Best,
Darshak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-10-2017 01:06 AM
Perfect. Code works . It's exatly job onDemand
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 06:55 AM
Hi Goran,
can you help my with this another query?
How can i modify your query for calculate first assigment?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2017 01:06 PM
How do you mean, you want to see how many of the RITM has true as first assignment?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2017 12:16 AM
I've done this script, but its not optimized:
var gr1 = new GlideRecord('u_history_task');
gr1.query();
while(gr1.next())
{
var gr2 = new GlideRecord('u_history_task');
gr2.addQuery('u_task',gr1.u_task);
gr2.addQuery('u_assignment_group',gr1.u_assignment_group);
gr2.orderBy('u_assignment_date');
gr2.setLimit(1);
gr2.query();
if(gr2.next())
{
gr2.u_first_assignment='true';
gr2.update();
}
}