calculated date in cstask
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 05:10 AM
Hi everyone,
I have catalog item where a variable end date (end_date, type = date) has to be filled in.
This catalog item has a flow that leads to 4 subflows.
In a subflow I want to create two task where the custom field scheluded end date (u_scheduled_end_date, type = date) should be filled with the item variable end_date + 28 days resp. 56 days.
I tried this script, but the field scheduled end date aren't filled.
// Retrieve the RITM from the current task
var ritmGr = new GlideRecord('sc_req_item');
if (ritmGr.get(current.request_item)) { // request_item contains the RITM sys_id
// Retrieve the end_date variable
var endDate = ritmGr.variables.end_date;
// Calculate the new date (24 days later)
var gdEndDate = new GlideDate();
gdEndDate.setValue(endDate);
gdEndDate.addDays(24); // Add 24 days
// Set the u_scheduled_end_date to the task
current.u_scheduled_end_date = gdEndDate.getValue(); // Date only (type Date)
current.update(); // Update the task with the new value
What else could I try?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 06:16 AM
where have you written this script?
are you creating a custom flow action and calling it from subflow?
the logic should be this
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-24-2024 07:59 AM
I create a Catalog task in an existing subflow (in the workflow editor).
Task table is sc_task.
I added the script in the 'advanced script'-section.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-24-2024 08:11 AM
is it a business rule or flow action?
please share some screenshots.
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-30-2024 06:43 AM
Dear Ankur,
I have attached some screenshots.
The first one is from the catalog item. The variable I want to take as starting point has the name end_date. This is a companies end date.
When this catalog item is submitted, a ritm is created togehter with a lot of catalog tasks. In the last picture you can find the taks where I want to have the scheduled end date filled in based on the given end date. As you can see, this field is ampty, even though I added UTC to the piece code, as you suggested.
The middle one is a screenshot of the summary of the catalog task so you can see the database name of this field.
So I want that, when the variable item end_date = january 1, 2025, two tasks are created with a scheduled and date +28 (2 weeks) and + 46 (4 weeks).
I hope I make myself clear.