- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 12:43 PM
I need to create a business rule to reject the change if it it not approved by the planned start date/time. I have written the following business rule but it isn't working. I'm new to scripting any help would be great. Thank you!
When to run: After Update
Condition: current.state == 'requested'
RejectPlannedDate (); |
function RejectPlannedDate ()
{
var approval = new GlideRecord("sysapproval_appover");
approval.addQuery('start_date' , '>=' , gs.current.start_date);
approval.query();
if (approval.next())
{
approval.state = 'rejected';
approval.update();
gs.addInfoMessage(gs.getMessage('Change rejected due to lack of approval by planned start date/time'));
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 01:33 PM
Not a "Wait for", but use a "Timer" activity instead and set the "Timer Based on" to "a date/time or duration field" and then select Planned Start Date as the field.
and then branch an activity off of that timer to reject the change automatically. That way, as soon as start_date is reached, the timer will kick off and expire the change if it is not already approved (you do need to make sure you check that the change is not already fully approved at that point). I would also reconsider setting the approval records as rejected. this may cause confusion where it may look like someone actually rejected when they didn't. instead, you could set the phase state to something that won't allow the change to progress until it is rescheduled.
this is exactly the solution we have done at my current company and works like a charm.
Jon
ps: if you want the change to show rejected exactly at the start_date if not fully approved, then a business rule would not give you that ability. Workflow or scheduled job is best, but scheduled job may be delayed as well, workflow is probably the best option for you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 12:52 PM
couple of things here...
1. gs.current.start_date would not be a valid object. You would want to compare the current date time (via gs.nowDateTime()) to the start_date of the current.sysapproval.start_date field.
2. I would add a condition to only run this for change_Requests by adding something like current.sysapproval.sys_class_name=='change_request'
3. I would recommend going about this a different way in any case. Instead of a business rule, which will only run when the sysapproval_approver record is updated, I would create a workflow, or update the one that is already running on change_request table that waits for the start_date to pass. once that is triggered, update phase of the change request from there. that way it won't be tied to a sysapproval_approver record getting updated.
Also, what table do you have this business rule running on? Change_request?
If you continue with this route for addressing this, you will also need to make sure you add a query to your gliderecord to find only sysapproval_approver records attached to this specific change_request: approval.addQuery('sysapproval',current.sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 01:04 PM
Thank you for the input- the route I was taking is definitely not the answer with your input...
But I cannot add a wait condition in our current workflow because I need the change to reject immediately if past the state date. Maybe my only route is a scheduled job but it seems this should be easier to solve.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 01:33 PM
Not a "Wait for", but use a "Timer" activity instead and set the "Timer Based on" to "a date/time or duration field" and then select Planned Start Date as the field.
and then branch an activity off of that timer to reject the change automatically. That way, as soon as start_date is reached, the timer will kick off and expire the change if it is not already approved (you do need to make sure you check that the change is not already fully approved at that point). I would also reconsider setting the approval records as rejected. this may cause confusion where it may look like someone actually rejected when they didn't. instead, you could set the phase state to something that won't allow the change to progress until it is rescheduled.
this is exactly the solution we have done at my current company and works like a charm.
Jon
ps: if you want the change to show rejected exactly at the start_date if not fully approved, then a business rule would not give you that ability. Workflow or scheduled job is best, but scheduled job may be delayed as well, workflow is probably the best option for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2016 01:53 PM
Thank you for going into more detail- I think the TIMER will work.
I completely agree with you about rethinking the rejected state- I am working on educating upper management that rejecting a change isn't the most efficient solution. Someday I hope to win that battle but I'm not a Change Manager .