Dates Validation using Client scripts and Data Policy

Lucky1
Tera Guru

Hello all,

 

On a change request, I want to make sure the difference between Start date and End date to be at least 15 mins but not below that.

It should be applicable during a change request record creation using Integration also.

So, I guess Data policy will work.

So, can someone please give me the code for this scenario.

 

 

Regards,

Lucky

1 ACCEPTED SOLUTION

Nishant8
Giga Sage

Hello @Lucky1 , You can write a Business Rule - configured to run before Insert and Update. you can use below script

 

(function executeRule(current, previous /*null when async*/) {
var startDate = current.work_start;
var endDate = current.work_end;
var startGDT = startDate.getGlideObject();
var endGDT = endDate.getGlideObject();
var compareTime = 900000; // 15 mins milliseconds
var duration = GlideDateTime.subtract(startGDT, endGDT).getNumericValue();
if (duration < compareTime) {
gs.addErrorMessage("Date difference should be more than 15 mins");
}
})(current, previous);

 

Regards,

Nishant

View solution in original post

14 REPLIES 14

Hello @Lucky1 , no its not required. its used when we dont want BR to run for specific logged in users. you can use the same script as i shared above (if field names are different then make changes accordingly).

 

Regards,

Nishant

Hello Nishant,

 

I will try this and get back to you.

 

 

Regards,

Lucky

@Lucky1 

if you want this BR to only run for integrations then use that check i.e. use not operator

!gs.getSession().isInteractive()

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Lucky1 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you Ankur very much,

 

 

Regards,

Lucky