Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business Rule won't run

Community Alums
Not applicable

I need to execute a Business Rule - when a certain catalog item is triggered from a particular Request type, eg., if the short description of the Request starts with "IT onboarding for". 

 

I have setup a business rule to run on Insert of the particular catalog item - and in the business rule itself wrote the below code to check the request's short description: 

 

    var check = new GlideRecord("sc_task");
    check.addEncodedQuery("cat_item=717ab6fd13b7f6042b3fXXXXXXXXX^request.short_descriptionSTARTSWITHIT onboarding request for");
    check.addQuery("sys_id", current.sys_id);
    check.query();

    if (check.next()) { 
	//Confirmed that its linked to "IT Onboarding request"
        //trigger the payload
}

 

But the Business Rule, simply won't run, if I enable the "Update" flag and test by updating the Task - it works, just not on Insert. Please advise!!!

5 REPLIES 5

aizawaken
Tera Guru

Hi @Community Alums ,
Still I don't have an answer to your question, but just let me clarify.

if I enable the "Update" flag and test by updating the Task  - it works, just not on Insert. 
So, do you set "sc_task" table for your triggering table? And also do you set "before" or "After" in When field?


I am just afraid that the new record is not yet inserted when your Business Rule runs,,,

Community Alums
Not applicable

Hi @aizawaken ! 

To answer your questions: 

 

> Yes, it works when I enable "Update" (on update) in the Business Rule, just not on Insert. 

> The table is "sc_task",  and its an "After" Business Rule, so After Insert. 

aizawaken
Tera Guru

Hi @Community Alums ,
I just tried same conditions as you mentioned, and it seems that it is working as expected.

aizawaken_2-1729091054832.png

 

aizawaken_1-1729090989000.png

aizawaken_4-1729091387598.png

aizawaken_5-1729091580216.png

 

Then, I could get the message as below.

aizawaken_3-1729091168916.png


Still I have not find out the root cause, but in my environment, your script runs fine.

Are there any difference between yours and mine?

Community Alums
Not applicable

Hi @aizawaken

The script is exactly the same - of course, within the IF loop - I'm triggering a Rest Outbound. This is my headache, logically it should run fine - but doesn't. Only difference I can think of - is that the REQ is created via humongous user provisioning script via a parent HRCASE ticket.