The CreatorCon Call for Content is officially open! Get started here.

Script only capturing the last row variable values and send via REST call

amamd
Tera Contributor

Script is only sending the last row of the variable values from a  multirow table.

Need to construct a json load to include variable values of all rows filled up in the multirow table. (could be  1 row to up to 5)

Below can have up to 5 body of data. 

GREEN text are only static ones, only the 5 Black bold values can repeat.

{
"input_vars": {
      "Template": [{
          "number": var1,
           "perh": var2,
           "ear": var3,
           "file": var4,
           "day": var5

},

{
           "number": var6,
           "perh": var7,
           "ear": var8,
           "file": var9,
           "day": var10

},

.

.

.

.

.

],
"work": "taskreq"
}
}

 

__________________________________________________________

var SysId = current.sys_id;

var jsons;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("sys_id", SysId);
gr.query();
if (gr.next()) {
jsons = gr.variables.Multirow_Set;
}
var parser = JSON.parse(jsons);
var lengths = parser.length;

 

for(var i = 0 ; i < parser.length; i++){

 

var var1 = parser[i].number;
var var2 = parser[i].perh;
var var3 = parser[i].ear;
var var4 = parser[i].file;
var var5 = parser[i].day;

 

var obj = {
"input_vars": {
"Template": [{
"number": var1,
"perh": var2,
"ear": var3,
"file": var4,
"day": var5
}],
"work": "taskreq"
}
};
}

var json = JSON.stringify(obj);

 

 

6 REPLIES 6

amamd
Tera Contributor

@Brad Bowman  

Could you pls look into the above where the payload is empty []

thanks

You should add some logs to the script so that you can see how far it is making it, the value of objArr, etc.  that should show you were it's going wrong.