In a Before Insert BR condition is not working

Chitradevi G
Tera Contributor

Hi,

I created a before insert BR on a sc_task table and gave a condition that item is equal to a particular catalog item.

In script section i simply wrote gs.log

but its not working.

BR is not even invoked.

Please suggest.

4 REPLIES 4

Jaspal Singh
Mega Patron
Mega Patron

Instead of adding it in codition try adding the code in the Advance condition as below

if(current.request_item.item.name=='ABC') //Replace ABC with item name

{

gs.log('in here');

}

ideamax
Mega Expert

Can you please show the script in the condition?

 

Use the below script

current.request_item.item == '<sys_id>' // sys_id of the catalog item

 

Mark correct and helpful if useful

 

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Share how are you giving the condition? screenshot etc

Also don't use gs.log() instead use gs.info();

It would be easier to use filter conditions in the BR directly

Regards
Ankur

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

Jorn van Beek
Tera Guru

First 2 thinks I think of why things go wrong:

  1. your condition is wrong, it is missing a point a equal sign, you validating name vs sys_id or so
  2. order of excution. the field is not filled at the moment you run the condition.

easiest way to debug.

I am against putting the condition in the script itself and not in the condition line like @Jaspal Singh suggested. But for debugging it is a good idea.

I would also place a gs.log / gs.info before the statement as well. that way you can be sure the br is running. It would look something like this:

var itemName = 'ABC' //Replace ABC with item name
gs.log('br running with item: ' + current.request_item.item.name + '\nExpecting if should be: ' + (current.request_item.item.name == itemName));

if(current.request_item.item.name == itemName){
	gs.log('br in if statement');
}

this should give you a log even if the condition is wrong. This will tell you that the br does run. Not that it is inactive or so.

Second it will give you what it expects from the if statement.

Third it will tell you if it gets into the if statement.

If this is not telling you what goes wrong then let us know the what the log statement are, then we can go from there