Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Create/Insert New Business Rule using custom Service Portal Widget

Learning Guy
Tera Contributor

Hello SNOW Community,

 

I have a very unique question. I'm currently building a custom data separation widget that's living on the Service Portal.  

 

I have a GlideRecord living on the Server Script page that is hitting the Business Rule [sys_script] table. 

 

Example:

//Create a new Business Rule record and populate the fields with the values below
var br = new GlideRecord('sys_script');
br.initialize();
br.name = "Query Group 19";
br.collection = input.parameterDefault; //<- Pulling selected table from select dropdown
br.active = true;
br.advanced = true;
br.when = "before";
br.order = 100;
br.action_query = true;
br.script = input.parameterWorkFlow; //<- pulling workflow script that needs to be added to Script section of BR 
br.insert();

 

I can create a Business Rule record and insert the name, table, set to Active, set to Advanced, but I can not insert a script into the Script section of the Business Rule. I have tried several iterations but keep hitting a brick wall.

 

I would really appreciate it, if anyone could provide technical advice on how to insert a custom script to the Script section of a Business Rule from a GlideRecord.  

 

Best

3 REPLIES 3

SanjivMeher
Mega Patron

Can you try

br.script = input.parameterWorkFlow+'';


Please mark this response as correct or helpful if it assisted you with your question.

Hi SanjivMeher,

 

Thank you for responding to my question. I used the statement you recommended, but I still got nothing to print to the Script section unfortunately.

Hey man... I just wanted to let you know I figured out why the custom script wasn't hitting the Script section.

 

To test a theory, I went and tried to drop the code in a Script Include, and when I did that, I saw a bunch of errors in the custom workflow script.

 

Once I went in and corrected the errors, I was able to get the script to work in the Script Include and Business Rule.

 

I really appreciate you trying to help. 

 

Always best