The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Set a date field on project task to a dynamic value using a template.

Chandler2
Tera Guru

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?

 

Chandler2_0-1667911774519.png

 

 

Thanks

9 REPLIES 9

Theo BOULANGER
Giga Guru

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 

TheoBOULANGER_0-1667912899066.png

 

And here is my function :

TheoBOULANGER_1-1667912925562.png

 

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

 

 

Theo BOULANGER
Giga Guru

Should be something like that, you have to see how you can filter the value in your table.

 

var gdt = new GlideDateTime();

if(gdt) {
    var actualDay = gdt.getDayOfMonth();
    var actualDayN10 = actualDay + 10;
    var filter = 'level=day^<choice>=' + actualDayN10; //depends OnYourFieldType but it should be something like that
    return filter;
}

return false;
 
You can create this function in a script include and call it in the reference qualifier like that :
javascipt:new nameOfYourScriptInclude.nameOfTheFunction()
 
If you're in a scoped app use this instead :
TheoBOULANGER_0-1667914253307.png

So javascript&colon;new API NAME(as you can see above).nameOftheFunction()

 

Regards,

 
 

Hi @Theo BOULANGER 

 

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);

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