Inserting data from a Multi-row variable set on a Record Producer into a Description field

Abdul30
Kilo Contributor

Hello, 

I am still very new to using the Multi-row variable set and am having some difficulty displaying the captured data to a record. Essentially I want to use the Multi-row variable set to create a Case (or any record) through the record producer and then display the content entered in the multi-row variable set into the description field (or any other text field) of that record. 

Is it possible to access the Mutli-row variable set data and loop through it row by row? 

Any help is much appreciated. 

Thanks,

Abdul

1 ACCEPTED SOLUTION

hollysnyder
Mega Guru

Hi Abdul,

I was able to get this working using this script in the script field on the Record Producer:

 

var varName = JSON.parse(producer.mrvs_name);
var description = '';
for(var i=0;i<varName.length;i++){
description += "\n Variable1: " + varName[i].variable1 + "\n Variable2: " + varName[i].variable2 + "\n Variable3: " + varName[i].variable3 + "\n";
}
current.case_field = description;

 

Hope this helps!

View solution in original post

20 REPLIES 20

Jace Benson
Mega Sage
The multirow variable set just stores the vale as a single string Igor’s json object. So yes

So how would one go about accessing that and displaying certain information into the description field? I guess I am not sure how to go about this through coding it from the record producers script field.

Thanks

It's an JSON.stringified array of objects.

So say your multirow variable set had the following variables;

Firstname, Lastname, Email

You're value of current.variables.people could be something like;

[{\"firstname\":\"Jace\",\"lastname\":\"Benson\",\"email\":\"jace@example.com\"},{\"firstname\":\"Abdul\",\"lastname\":\"Aaron\",\"email\":\"abdul@example.com\"},{\"firstname\":\"Brandon\",\"lastname\":\"Brennan\",\"email\":\"brandon@example.com\"},{\"firstname\":\"Charlie\",\"lastname\":\"Carpenter\",\"email\":\"charlie@example.com\"}]

However if you just do JSON.parse(current.variables.people) you'll get this;

[
    {
        "firstname": "Jace",
        "lastname": "Benson",
        "email":"jace@example.com"
    },
    {
        "firstname": "Abdul",
        "lastname": "Aaron",
        "email":"abdul@example.com"
    },
    {
        "firstname": "Brandon",
        "lastname": "Brennan",
        "email":"brandon@example.com"
    },
    {
        "firstname": "Charlie",
        "lastname": "Carpenter",
        "email":"charlie@example.com"
    },
]

Once you have that you can do a forEach, map, or for loop to go over it;

// the below is for testing in the browsers console
var current = {
  variables: {
    people: "[{\"firstname\":\"Jace\",\"lastname\":\"Benson\",\"email\":\"jace@example.com\"},{\"firstname\":\"Abdul\",\"lastname\":\"Aaron\",\"email\":\"abdul@example.com\"},{\"firstname\":\"Brandon\",\"lastname\":\"Brennan\",\"email\":\"brandon@example.com\"},{\"firstname\":\"Charlie\",\"lastname\":\"Carpenter\",\"email\":\"charlie@example.com\"}]"
  }
}
// the above is for testing in the browsers console
// you're current.variables.multirowvariablename will have similiar data
var people = JSON.parse(current.variables.people);// this is now the nice array
for(var x = 0;x<people.length;x++){
  var message = "Person at position " + x + " is ";
  message += people[x].firstname + " " + people[x].lastname;
  console.log(message); 
}
/**
Output is;
Person at position 0 is Jace Benson debugger eval code:13:3
Person at position 1 is Abdul Aaron debugger eval code:13:3
Person at position 2 is Brandon Brennan debugger eval code:13:3
Person at position 3 is Charlie Carpenter
**/

Thanks jace, I have yet to implement this but I will give it a try soon and let you know how it goes. I appreciate the help