How to use variable set variables in a payload for a Rest Message?

Jesus Nava
Tera Guru

Hello experts please I need your help, I have a catalog item that used regular variables, once the item ordered, a BR would execute to post a message via REST i, here is the piece of code and it is actually working:

find_real_file.png

as you see in the payload there is the "variables" that will fetch from the catalog item variables.

My issue here is that I modified the catalog item and instead of variables I used a variable set and it is not fetching the variables from the variable set, how can I add the variables from the variable set?

this is the current Outbound HTTP result:

{"Variables":"{\"Variables\":[{\"Requested For\":\"XXXXX\",\"Description\":\"Testing\",\"Reminder: please open a new case for this\":\"\"}]}","attachments":[{"Caller":"XXXXXX","Short Description":"Request Delivery","title":"SCTASK0000001","title_link":"https://mycompany.service-now.com/api/now/table/sc_task?sys_id=f99a926a87c5d51074c731dd3fbb3569"}],"text":"Request has been assigned to the group: ServiceDesk"}

As you see only 3 variables show Requested for, Description and Reminder. I'm missing the variables from the vatiable set I created, coyld you guide me on how to do it?

Thank you

1 ACCEPTED SOLUTION

Hi @Jesus Nava 

then you need to parse the json string and get the value

something like this

var ritmSysId = current.request_item;

var jsonString;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", ritmSysId);
gr.query();
if (gr.next()) {
   jsonString = gr.variables.variableSetName; // give MRVS variable set name here
}

var parser = JSON.parse(jsonString);

var variableValue = parser[0].variableName; // give name of variable within MRVS

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Hello Ankur, yes it's a multi-row variable set, how can I make it work?

Regards

Hi @Jesus Nava 

then you need to parse the json string and get the value

something like this

var ritmSysId = current.request_item;

var jsonString;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", ritmSysId);
gr.query();
if (gr.next()) {
   jsonString = gr.variables.variableSetName; // give MRVS variable set name here
}

var parser = JSON.parse(jsonString);

var variableValue = parser[0].variableName; // give name of variable within MRVS

Regards
Ankur

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

Thank you for all your support!

Mohith Devatte
Tera Sage
Tera Sage

hello @Jesus Nava ,

i can see the arr.push(obj); which you might have used to store the variables in obj JSON.

CAN YOU SEND THAT PART HOW ARE CONSTRUCTING THE JSON MAY BE WE CAN HELP YOU AFTER SEEING IT ?

Thank you Monith, I posted it

Regards