- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2020 10:38 AM
Hi Folks,
I have a custom field "When Needed" on the incident in which I need validation if user tries to inout today's date or date in the past It should show an error message while submitting. How can it can be achieved using BR.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2020 10:42 AM
Configure the Business Rule as below
Name: XYZ
Table: incident ["incident"]
Active: Selected (checked)
Advanced: Selected (checked)
Switch to the When to run section and continue configuring the Business Rule:
When: Before
Insert: Selected (checked)
// rightnow stores the current time
var rightnow = new GlideDateTime();
// Create a GlideDateTime object for the When needed date
var whenNeeded = new GlideDateTime(current.needed_field_name_here);
var today = rightnow.getLocalDate();
var istoday = whenNeeded.getLocalDate();
// If the When needed date is before rightnow, do not write the record to the database and Compare today and istoday to see if they are the same day
// show an error message to the screen
if(whenNeeded.before(rightnow) || (today.compareTo(istoday) == 0)){
gs.addErrorMessage("Your message");
current.setAbortAction(true);
}
Kindly let me know it helped your queries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2020 10:42 AM
Configure the Business Rule as below
Name: XYZ
Table: incident ["incident"]
Active: Selected (checked)
Advanced: Selected (checked)
Switch to the When to run section and continue configuring the Business Rule:
When: Before
Insert: Selected (checked)
// rightnow stores the current time
var rightnow = new GlideDateTime();
// Create a GlideDateTime object for the When needed date
var whenNeeded = new GlideDateTime(current.needed_field_name_here);
var today = rightnow.getLocalDate();
var istoday = whenNeeded.getLocalDate();
// If the When needed date is before rightnow, do not write the record to the database and Compare today and istoday to see if they are the same day
// show an error message to the screen
if(whenNeeded.before(rightnow) || (today.compareTo(istoday) == 0)){
gs.addErrorMessage("Your message");
current.setAbortAction(true);
}
Kindly let me know it helped your queries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2020 11:24 PM
Thank you Danish the code worked successfully.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2020 10:44 AM
Hi Ashwini,
In this case better would be client script or UI policy as Business rule would run when form is tried to saved or submitted thus at times being frustating for user as it would be after filling all details error would be popped.
A simple UI Policy would suffice where you can specify the conditin as
When Needed before Today
& in the script you can add
function onCondition()
{
alert('When Date cannot be before Today or Past date');
g_form.setClearValue('u_when_date');
}
Thanks,
Jaspal Singh
Hit Helpful or Correct on the impact of response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2020 11:24 PM
Hi Jaspal,
Thanks for your valuable time,I wanted to show the message on submission.