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-08-2022 05:09 AM
Hello @Chandler2 ,
You can use Reference qualifier in Type Specifications when configuring your field in the table.
For exemple here I wanted to be able to select year one year after actual one.
Here is my Reference qualifier calling my script Include's function
And here is my function :
I think you can just change the logic to get what you want.
If you need more help don't hesitate to tell me and if my answer is helpfull don't forget to hit the like button !
Regards,
Theo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2022 05:32 AM
Should be something like that, you have to see how you can filter the value in your table.
So javascript:new API NAME(as you can see above).nameOftheFunction()
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 08:44 AM
I was trying with a BR (After Insert) but for sure the script include will be a better option.
Below is my code in BR and I don't think addMonthsLocalTime is working.
If you have some mins to correct this code for the script include function?
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var planDate = current.start_date;
var gr = new GlideRecord("pm_project_task");
gr.addQuery("parent", "current.sys_id");
gr.addEncodedQuery('short_description=Test my code');
gr.query();
if (gr.next()) {
gr.start_date = planDate.addMonthsLocalTime(1);
}
gr.update();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 12:59 AM
I don't think this BR is a good idea, did you try my solution above ?
Doing a custom filter to prevent user to choose a day you don't want should be the solution you need and it's more maintainable.
By the way, maybe there'll be an error when you arrive at the end of the month so the +10 day won't work but you have to try it.
If there's an error you'll have to do an if condition to start on the next month 🙂
Regards,
Theo