Set a date field on project task to a dynamic value using a template.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 04:49 AM
So, I am creating project and project tasks using a template. There I want to select the date of the project task to few days ahead of the project start date. The date field option is a simple calendar selection. How can I make it dynamic like set the value to 10 days from now?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:05 AM
@Theo BOULANGER I think my question was little unclear.
There is a template to create project which create and project tasks. Now while creating project, we have to select a start date. Now If I select start date as 01-11-2022 then all the project tasks also get created with same start date.
My requirement is that one of the project task (based on condition like, name is xyz) should have start date which is 1 month ahead. For eg: I choose 17-11- 2022 in the template so that particular task xyz should have a date 17-12-2022.
Now below is the BR that i used on after insert BR and it works but I want to use a script include as you suggested. Just thinking on how will I get the Top Project info in script include.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var currentTime = new GlideDateTime(current.start_date);
currentTime.addMonthsUTC(1);
var gr = new GlideRecord("pm_project_task");
gr.addQuery("top_task", current.sys_id);
gr.addEncodedQuery('short_description=xyz');
gr.query();
if (gr.next()) {
gr.start_date = currentTime;
}
gr.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:30 AM
If it is working with BR then I don't think you need to have script inlcude.
However, if you still need it then you can pass current object in script include as below,
new ScriptInlcludeName().functionName(current);
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 02:59 AM
@Abhijit4 Can you please elaborate.
I can put below code in the function in script include but how I will get the start date from the corresponding parent project record?
var gr = new GlideRecord("pm_project_task");
gr.addQuery("top_task", current.sys_id);
gr.addEncodedQuery('short_description=xyz');
gr.query();
if (gr.next()) {
gr.start_date = currentTime;
}
gr.update();
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 03:14 AM
You need to call script include function via BR as shown below :
BR script :
new global.SetStartDate().SetStartDate(current);
Script Include :
Please mark answer as Correct or Helpful based on impact.
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 03:06 AM
Script include :