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.

How to get the variables values of the catalog item using Business Rule

Alon Grod
Tera Expert

Hi,

I have an advanced on before insert BR on the sc_task table. Im trying to get the variable's value (password) from the catalog item but Im getting undefined in the logs. What am I doing wrong?

 

BR: 

WhatsApp Image 2023-08-07 at 08.06.55.jpeg


 Catalog Item:

WhatsApp Image 2023-08-07 at 08.07.16.jpeg

 

Catalog task:

WhatsApp Image 2023-08-07 at 08.12.07.jpeg


Logs:

WhatsApp Image 2023-08-07 at 08.07.33.jpeg

3 REPLIES 3

Rahul Talreja
Mega Sage

Hi @Alon Grod ,
Methods to call catalog item variables is different.
Can you try changing your script reffering this:

 

 

var now_GR = new GlideRecord('sc_req_item'); 
if (now_GR.get('03bc19e11bc90510ee770f2f5b4bcba5')) { 
    var variables = now_GR.variables.getElements(); 
    for (var i=0;i<variables.length;i++) { 
        var question = variables[i].getQuestion(); 
        gs.log(question.getLabel() + ":" + question.getValue()) 
    } 
}

 

You can also refer to link - Scriptable service catalog variables (servicenow.com)

For your use case:

var now_GR = new GlideRecord('sc_req_item'); 
now_GR.get('03bc19e11bc90510ee770f2f5b4bcba5');
var temp = now_GR.variables.getElements()[1].getQuestion().getValue();

 

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Rahul Talreja
Mega Sage

Hi @Alon Grod ,
Were you able to get the desired output?

Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul

Prince Arora
Tera Sage

@Alon Grod 

 

Can you try making the Business rule After-insert and let me know if it works(I haven't tried it)