- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:46 AM
For example, I have added a new field (abc) in change requests form, this abc field is already available in all change tasks form so I have to get the abc field value from all the change tasks and display the maximum value in the abc field of change request form. How will I query it?
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 03:14 AM
Hi Aishwarya,
Could you please tell me if this solution is for old data or you want to make a generic solution.
For old data you can write a Background script or fix script as shown below:
var ctask = new GlideRecord('change_task');
ctask.query();
while(ctask.query()){
var change = new GlideRecord('change_request');
change.addQuery('sys_id',ctask.change_request);
change.query();
if(change.next()){
if(change.abc<ctask.abc){ //instead of abc please use your field name
change.abc = ctask.abc;
change.setWorkflow(false);
change.update();
}
}
}
Generic Solution:
As
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var change = new GlideRecord('change_request');
change.addQuery('sys_id', current.change_request);
change.query();
if (change.next()) {
if (change.abc < current.abc) { //instead of abc please use your field name
change.abc = current.abc;
change.update();
}
}
})(current, previous);
Please mark this as correct and helpful if it resolved the query or lead you in right direction.
Thanks,
Mohit Kaushik
Community Rising Star 2022
Mohit Kaushik
ServiceNow MVP (2023-2025)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:50 AM
You have to write a after insert/update BR on change task table, through which you will check the value on the Change new field to compare if the value on task is greater than the one in change, if found, you will update the Change new field.
For example, you will have no value in change new field, once a change task is created it will check if it is empty, it will update the value, if more change tasks are created, it will check the value in change new field and so on.
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 12:58 AM
Actually I should compare all the change tasks value, not change task with change request form
For example:
Change task 1--> abc field value = 2
Change task 2--> abc field value = 3
Change task 3--> abc field value = 1
Max value of these change tasks is 3 (from change task 2)
so now query should compare these 3 change tasks value and display the max value in the abc field of change request form

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 01:02 AM
That is fine, the logic that I mentioned will run on each insert/update of change task or change in these values,
lets say:
change task 1 value is 1 , it will update the change value as 1
change task 2 value is 2, it will update the change value as 2
change task 3 value is 1, it won't make any update to change new value
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2022 03:14 AM
Hi Aishwarya,
Could you please tell me if this solution is for old data or you want to make a generic solution.
For old data you can write a Background script or fix script as shown below:
var ctask = new GlideRecord('change_task');
ctask.query();
while(ctask.query()){
var change = new GlideRecord('change_request');
change.addQuery('sys_id',ctask.change_request);
change.query();
if(change.next()){
if(change.abc<ctask.abc){ //instead of abc please use your field name
change.abc = ctask.abc;
change.setWorkflow(false);
change.update();
}
}
}
Generic Solution:
As
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var change = new GlideRecord('change_request');
change.addQuery('sys_id', current.change_request);
change.query();
if (change.next()) {
if (change.abc < current.abc) { //instead of abc please use your field name
change.abc = current.abc;
change.update();
}
}
})(current, previous);
Please mark this as correct and helpful if it resolved the query or lead you in right direction.
Thanks,
Mohit Kaushik
Community Rising Star 2022
Mohit Kaushik
ServiceNow MVP (2023-2025)