Due date on sc_task form should be one day prior to start date

C_S3
Tera Contributor

Hello All,
We have an requirement ,where when user will enter the start date on form ( catalog item form ) then after submitting the form, the due date field on sc_task form should be one day prior to start date.
Any help would be appreciated.
Thank you!

5 REPLIES 5

shyamkumar VK
Kilo Patron

Hi @C_S3 ,

Use before update/insert  business rule on the sc_task table and give specific condition when it needs to update.

Use below script on business rule

 

(function executeRule(current, previous /*null when async*/ ) {

    var startdate = current.variables.start_date;

    var dt = new GlideTime();
    var time = dt.getDisplayValue().split(' ')[1];//get time
    var finaldatetime = startdate + ' ' + time; //it will give start date and time

    var gdt = new GlideDateTime(finaldatetime); //using finaldatetime to subtract 1 day from start date
    gdt.addDays(-1); //substract 1 day
    current.due_date = gdt;//update on due date field 

})(current, previous);

Note: place your correct backend values in script 

If this solution worked for you, please mark this as helpful & accept the solution as correct!
Regards,
Shyamkumar

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

Hemanth M1
Giga Sage
Giga Sage

Hi @C_S3 ,

 

Are you looking for a logic to get start date from the catalog item variable and set 1 day prior (Start date entered) on the catalog task???

 

Can we know how are you creating the catalog task so that we can provide script to update.

 

to begin with to retrive the start date entered use -- varibaleobject.variables.start_date (ex: current.variables.start_date)

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

C_S3
Tera Contributor

Hello @Hemanth M1 ,

We are creating sc_task using flow designer.

 

Great

Use script to set due date as below :

HemanthM1_1-1693301255644.png

 

 

var date = fd_data._1__get_catalog_variables.start_date; //get start date from the variable
var gdt = new GlideDateTime(date);
gdt.addDays(-1); // substract a day
gdt =gdt.toString();
return gdt;

 

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025