HRSD flow automation

nayanmule
Tera Expert

Hello Everyone,

 

I have a requirement in HRSD.  

We have a form (record producer) where we have 3 dates and based on selection of the dates we have to create the HR tasks.

Eg. if Date 1 is selected anything in future, HR task should be created 2 weeks before the selected date.

If the selected Date1 is already within 2 weeks from the current date, it should directly create a task.

 

Likewise, this should work for Date 2 and Date 3.

I was trying this using flow designer but I need a help while checking the date conditions.

 

Any help will be appreciated.

 

Thanks,

Nayan

2 REPLIES 2

Bhuvan
Kilo Patron

@nayanmule 

 

Try to use below for date comparison in Flow,

 

https://www.servicenow.com/community/developer-articles/date-difference-in-flow-designer/ta-p/229620...

 

If you import the XML, you will get Date Compare as an action that can be used to extend your logic. Testing in PDI or lower environment first and if it works for you, migrate it.

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

M Iftikhar
Kilo Sage

Hi @nayanmule ,

You can definitely handle this in Flow Designer by adding date logic before creating the HR tasks. A general approach would be:

  1. Trigger: Record Producer → When submitted, trigger your flow.

  2. For each date field (Date1, Date2, Date3):

    • Add a Script step or Date Compare action (using the following link) to compare the selected date with today.Date difference in Flow Designer - ServiceNow Community

    • Logic you need:

      • If the selected date ≥ (today + 14 days): subtract 14 days and set that as the due/start date for the HR Task.

      • If the selected date < (today + 14 days): create the task immediately (using today’s date).

  3. Create HR Task action: Use the calculated date to populate the “Due Date” or whichever field you want to drive the timing.

For the condition check, you can use a Flow Designer Script step like this (example for Date1):

(function execute(inputs, outputs) {
    var today = new GlideDate();
    var futureDate = new GlideDate();
    futureDate.addDays(14);

    var selectedDate = new GlideDate();
    selectedDate.setValue(inputs.date1);

    if (selectedDate.compareTo(futureDate) >= 0) {
        // Selected date is more than 2 weeks away
        selectedDate.addDays(-14);
        outputs.taskDate = selectedDate;
    } else {
        // Selected date is within 2 weeks
        outputs.taskDate = today;
    }
})(inputs, outputs);


Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.