Populate Assignent group based on ticket created time

VenkateshA42034
Tera Contributor

I need to fill the assignment group based on the invoice created time using flow designer in servicenow.

If the invoice is created between 3 pm and 6.59 am IST it should assign to Evening shift group or else it should assign to morning shift group.

3 REPLIES 3

maliksneha9
Mega Sage

To achieve this in ServiceNow Flow Designer, the most reliable approach is to use a Custom Script Action. Since standard Flow Designer condition builders don't handle specific time-of-day logic across day boundaries, a small script snippet is the most efficient way to handle it.

 

Add a "Script" step to your flow to determine the shift. This avoids complex "If/Else" nesting.

(function execute(inputs, outputs) {
var gdt = new GlideDateTime(inputs.created_at);

// Convert UTC to IST (Add 5 hours and 30 mins)
var tz = Packages.java.util.TimeZone.getTimeZone("Asia/Kolkata");
gdt.setTZ(tz);

// Get the hour of the day in 24-hour format (0-23)
var hour = parseInt(gdt.getTime().getByFormat('HH'));

// Logic: 3 PM (15:00) to 6:59 AM (06:00)
// This means if hour >= 15 OR hour <= 6, it is Evening Shift.
if (hour >= 15 || hour <= 6) {
outputs.shift = "Evening Shift Group";
} else {
outputs.shift = "Morning Shift Group";
}
})(inputs, outputs);

 

 

Tanushree Maiti
Kilo Patron

Hi @VenkateshA42034 

 

Use a Flow Logic IF with a script to check
if the sys_created_on falls between 15:00:00 and 06:59:59.

Assign to "Evening Shift" if true,
else "Morning Shift" using Update Record.

 

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

SohamTipnis
Mega Sage

Hi @VenkateshA42034,

 

You can do this easily in Flow Designer using a condition on the created time.

Basically, your logic is:

If the invoice is created after 3 PM OR before 7 AM, assign it to the Evening shift group

Otherwise, assign it to the Morning shift group

The reason we use OR is because your time range crosses midnight.

So in the flow:

Add a Decision step

Check the time part of sys_created_on

If it matches that condition, set Assignment Group = Evening

Else → set Assignment Group = Morning

Just make sure your instance/user timezone is set to IST; otherwise, the timing may not match your requirement.

 

Let me know if this works!!!!😀

 

If you find my answer useful, please mark it as Helpful and Correct. ‌‌‌‌‌‌‌‌‌😊


Regards,
Soham Tipnis
ServiceNow Developer ||  Technical Consultant
LinkedIn: www.linkedin.com/in/sohamtipnis10