- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 12:03 AM - edited 12-23-2024 12:07 AM
const scTaskGr = new GlideRecord('sc_task');
scTaskGr.addActiveQuery();
scTaskGr.addQuery('cat_item', '55ae8727e05b461093590cbbafe05143');
scTaskGr.addQuery('request_item.stage', 'fulfillment');
scTaskGr.query();
while (scTaskGr.next()) {
const start = scTaskGr.variables.target_commencement_date;
const end = scTaskGr.variables.target_completion_date;
scTaskGr.variables.days_left_before_target_completion_date = GlideDate.subtract(start, end).getDisplayValue();
scTaskGr.updateWithReferences();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 01:03 AM
then store the duration
const scTaskGr = new GlideRecord('sc_task');
scTaskGr.addActiveQuery();
scTaskGr.addQuery('cat_item', '55ae8727e05b461093590cbbafe05143');
scTaskGr.addQuery('request_item.stage', 'fulfillment');
scTaskGr.query();
while (scTaskGr.next()) {
const start = scTaskGr.variables.target_commencement_date;
const end = scTaskGr.variables.target_completion_date;
var ritm = new GlideRecord('sc_req_item');
ritm.get(scTaskGr.request_item);
ritm.variables.days_left_before_target_completion_date = GlideDate.subtract(start, end).getDisplayValue();
ritm.update();
}
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
12-26-2024 10:23 PM
Hi,
Thanks for this, but this one worked for me. I've used var instead of const inside the while loop. And I've accessed the variables in sc_task table.
gs.info('Set Remaining Days Left Before Target Completion Date Scheduled Job is running...');
var scTaskGr = new GlideRecord('sc_task');
scTaskGr.addActiveQuery();
scTaskGr.addQuery('cat_item', '55ae8727e05b461093590cbbafe05143');
scTaskGr.addQuery('request_item.stage', 'fulfillment');
scTaskGr.orderBy('number');
scTaskGr.query();
gs.info('Row Count: ' + scTaskGr.getRowCount());
while (scTaskGr.next()) {
// gs.info('Current: ' + scTaskGr.variables.days_left_completion_date);
var start = new GlideDate();
start.setValue(scTaskGr.variables.target_commencement_date);
var end = new GlideDate();
end.setValue(scTaskGr.variables.target_completion_date);
var daysLeft = GlideDate.subtract(start, end);
gs.info('SCTASK Number: ' + scTaskGr.number);
gs.info('Target Commencement Date: ' + start);
gs.info('Target Completion Date: ' + end + '\n');
gs.info("Days Left: " + daysLeft.getDisplayValue());
if (start.getDisplayValue() == end.getDisplayValue()) {
scTaskGr.variables.days_left_completion_date = '0 Day';
} else {
scTaskGr.variables.days_left_completion_date = daysLeft.getDisplayValue();
}
scTaskGr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 12:34 AM
yes it's possible
but difference between 2 dates will be duration
what's the variable type for Days Before Target Completion Date?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 12:34 AM
Hi,
its single-line text with no validation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2024 01:03 AM
then store the duration
const scTaskGr = new GlideRecord('sc_task');
scTaskGr.addActiveQuery();
scTaskGr.addQuery('cat_item', '55ae8727e05b461093590cbbafe05143');
scTaskGr.addQuery('request_item.stage', 'fulfillment');
scTaskGr.query();
while (scTaskGr.next()) {
const start = scTaskGr.variables.target_commencement_date;
const end = scTaskGr.variables.target_completion_date;
var ritm = new GlideRecord('sc_req_item');
ritm.get(scTaskGr.request_item);
ritm.variables.days_left_before_target_completion_date = GlideDate.subtract(start, end).getDisplayValue();
ritm.update();
}
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
12-23-2024 10:23 PM
Hope you are doing good.
Did my reply answer your question?
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