Before Insert/Update Business Rule not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 12:00 PM
Hi,
I am trying to populate the 'fiscal period' on Requested allocation based on start date and end date through before Insert/Update BR but it's not working. This BR is not running at all. Can someone please help me with this ?
Requested allocation record gets created when we submit resource plan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 12:12 PM
Try running your script as a background script and instead of current.something you just log the value (gs.info(values)) to see what it contains.
If your query is not returning anything, then you'd be able to see that right away in the background script.
Also, to make sure your BR is running, you can just add couple of gs.info() logs to the start and end and see if what you're logging shows up in the log table.
For example
gs.info("Starting BR");
your code
gs.info("Finishing BR");
This would rightaway show you that your script started and finished without stopping.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 12:16 PM
Thanks, but this BR is working on Before update condition. If I am updating any values on requested allocation, Fiscal period is getting populated and log is coming so this BR is working on before update. The problem is with Before Insert, when Requested allocation record gets created at that time I need to populate fiscal period value. which is not working.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 06:39 PM
Try updating the script as follows.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var AllocStartDate = new GlideDateTime(current.start_date) + " 00:00:00";
var AllocEndDate = new GlideDateTime(current.end_date) + " 23:59:59";
var fsp = new GlideRecord('fiscal_period');
fsp.addEncodedQuery("fiscal_start_date_time<=" + AllocStartDate + "^fiscal_end_date_time>=" + AllocEndDate + "^fiscal_type=445period");
fsp.query();
if (fsp.next()) {
current.u_fiscal_period = fsp.getValue('sys_id');
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2023 06:57 PM
Hi Sandeep,
I tried this change but issue still persist. I have changed the order of the BR as well (tried from 20 to 950 but still same). Is there any other way I can achieve this functionality ?