- 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 10:48 PM
@Siddharth Parna you just need to make sure you:
the correct sys_id of the group (not its name) used, Reference the field properly in your addQuery() condition. and Place the filter before the query() call.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:24 PM
- The query method should be called with parentheses to execute the query.
- Ensure that the request_item field is correctly referenced and exists in the sc_task table.
- Ensure that the short_description variable exists in the sc_req_item table.
try this corrected script:
var taskgr = new GlideRecord('sc_task');
// Uncomment and set the appropriate group ID if needed
// 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);
}
}
}
}
If my response helped, please hit the 👍Thumb Icon and accept the solution so that it benefits future readers.
Regards,
Mohd Arbaz.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 10:03 PM
@Siddharth Parna If my response helped, please mark it as helpful and accept it as one more solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2025 09:31 PM
- taskgr.query(); - You missed the parentheses, so the query was never executed.
- reqItem.get(taskgr.request_item.toString()) - Ensures the correct sys_id is passed
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.