Capturing data of a variable set in a record producer

Mohammad8
Kilo Expert

Hi All,

I have a record producer that contains some fields. Every field maps to a corresponding field in my table. I also have a multi-row variable set but it cannot be mapped to a particular field in my table. The normal fields go straight to my table when the record producer form is submitted, the only problem I have is with the variable set. I don't know how to capture it data. Any help is this?

 

Thanks in advance

1 ACCEPTED SOLUTION

Okay, fine.

Go to your record producer as admin.

Under "What it will contain", you will see  a script field.

This will be executed after the record producer is submitted.

So here you can access the variable set data using like below

var variable1 = gr.variables.table_var.var1; //table_var is multi row set name and var1 is the variable name inside the variable set.

Once you access this value, where do you want to store this data? In which table and fields you want to store it?

if you want to store in custom table, then use code like below

var cust = new GlideRecord("your_table");

cust.initialize();

cust.field_name = variable1;

cust.insert();

Also, i suggest you to check out the OOB record producers where multi row variable set is used and see how they are being used.

Mark the comment as a correct answer and also helpful once worked.

View solution in original post

6 REPLIES 6

asifnoor
Kilo Patron

You capture the data in the variable set and then in the record producer script, get the value of the variable set which i think you will get in json format. Parse the json and then loop through it and store it in the fields in which you want them to. 

Mark the comment as a correct answer and helpful if it helps.

I don't know how to capture the data. This is why I'm asking the question 🙂

Ah okay.

Refer to this link and look for section "Multi-row variable set". It has all the code snippets to access the data.

https://docs.servicenow.com/bundle/london-application-development/page/script/server-scripting/conce...

Mark the comment as a correct answer and also helpful if it helps.

I'm kind of new to ServiceNow. I went through this article and particularly to the section you recommended but I don't understand it. I don't know where to add this code. I would highly appreciated if you can tell me step by step what to do. For example, should I create a business rule or what? I don't know where to begin.