Before Insert/Update Business Rule not working as expected

SnowSB
Tera Contributor

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.

 

SnowSB_0-1700942395028.png

 

 

SnowSB_1-1700942395029.png

 

 

SnowSB_2-1700942395030.png

 

 

4 REPLIES 4

Weird
Mega Sage

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.

SnowSB
Tera Contributor

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.

Sandeep Rajput
Tera Patron
Tera Patron

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);

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 ?