- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:16 PM
var taskgr = new GlideRecord('sc_task');
//taskgr.addQuery('assignment_group', 'Group id ');
taskgr.setLimit(5);
taskgr.query;
while (taskgr.next()) {
if(taskgr.request_item){
gs.info('Task Number:' + taskgr.number);
var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(taskgr.request_item)) {
var shortDesc = reqItem.variables.short_description;
if (shortDesc) {
taskgr.u_short_description = shortDesc.toString();
taskgr.update();
gs.info('Updated Task' + taskgr.number);
} else {
gs.info('No Short Description:' + taskgr.number);
}
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:22 PM
verify the updated script:
var taskgr = new GlideRecord('sc_task');
taskgr.setLimit(5);
taskgr.query(); // <-- Fix here
while (taskgr.next()) {
if (taskgr.request_item) {
gs.info('Task Number: ' + taskgr.number);
var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(taskgr.request_item.toString())) { // <-- Add .toString()
var shortDesc = reqItem.variables.short_description;
if (shortDesc) {
taskgr.u_short_description = shortDesc.toString();
taskgr.update();
gs.info('Updated Task: ' + taskgr.number);
} else {
gs.info('No Short Description for Task: ' + taskgr.number);
}
} else {
gs.info('Requested item not found for Task: ' + taskgr.number);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:22 PM
verify the updated script:
var taskgr = new GlideRecord('sc_task');
taskgr.setLimit(5);
taskgr.query(); // <-- Fix here
while (taskgr.next()) {
if (taskgr.request_item) {
gs.info('Task Number: ' + taskgr.number);
var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(taskgr.request_item.toString())) { // <-- Add .toString()
var shortDesc = reqItem.variables.short_description;
if (shortDesc) {
taskgr.u_short_description = shortDesc.toString();
taskgr.update();
gs.info('Updated Task: ' + taskgr.number);
} else {
gs.info('No Short Description for Task: ' + taskgr.number);
}
} else {
gs.info('Requested item not found for Task: ' + taskgr.number);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:35 PM
This works.Can you also let me know how to filter based on assignment group as mentioned in the comments.I tried giving the id ,but I see when added filter records dont get updated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:42 PM
try this for your earlier question and subsequent question as well and give correct group sysId
var taskgr = new GlideRecord('sc_task');
// Replace 'GROUP_SYSID' with the actual sys_id of the assignment group you want to filter by
taskgr.addQuery('assignment_group', 'GROUP_SYSID');
taskgr.setLimit(5);
taskgr.query();
while (taskgr.next()) {
if (taskgr.request_item) {
gs.info('Task Number: ' + taskgr.number);
var reqItem = new GlideRecord('sc_req_item');
if (reqItem.get(taskgr.request_item)) {
var shortDesc = reqItem.variables.short_description;
if (shortDesc) {
taskgr.u_short_description = shortDesc.toString();
taskgr.update();
gs.info('Updated Task: ' + taskgr.number);
} else {
gs.info('No Short Description: ' + taskgr.number);
}
}
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:52 PM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader