How to get variables from Input records in Flow Action Script Step?

Daemon5
Tera Expert

Hi!
I have not been able to solve this problem for a long time and would like to know if you can help me.

 

I made custom Action for the purpose of converting Record type Input to Array.Object Output.
I think I may have succeed to comma-separate the Input and process it so that it goes into an Array.Object type.

 

But I couldn't get the Record`s variable and the test says [undenied][undenied][undenied]...

 Input value "records" refers "Table contains list column", and "Table contains list column" have List variable "u_list_test_column".

And the "u_list_test_column" refers 3 Strings from Table "Table contains string colummn".


If you know of a script that can take variables from the records, I would be glad to know.
Thank you.

1 ACCEPTED SOLUTION

Daemon5
Tera Expert

I could convert List type to Object.Array by making new Action.

Here`s script. Eureka!

(function execute(inputs, outputs) {
  //Create an empty array
  var valueinfoArray = [];
  var i = 0;
  //Iterate through the list of User records
  while(inputs.records.next()) {
    //Create an empty object for each iteration
    var contactObject = {};
    //Query User records to assign object values
    contactObject.string1 = inputs.records.getValue('u_string1');
    contactObject.string2 = inputs.records.getValue('u_string2');
    contactObject.string3 = inputs.records.getValue('u_string3');
    //Add current object to array
    valueinfoArray[i] = contactObject;
    i += 1;
  }
  outputs.valueinfo = valueinfoArray;
})(inputs, outputs);

 

View solution in original post

5 REPLIES 5

Mark Manders
Mega Patron

I think you mean 'undefined' instead of 'undenied'?

 

I ran into something similar and changed the entire input to being a record type, with input set as documentID and table name and from there I was able to get everything I needed for my script. Just not sure if that will help you (depending on what you need as output).


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Thank you! I misspelled "undefined" as you can see in the screenshot.

In my previous question, I have succeeded in comma-separate the List type Input and convert to Array.Object Output, but this could only take a single value in the Flow, not multiple record values.
So I changed Input value to Record type and trying to get the value directly from Record using script, but this  not working properly.

Mark Manders
Mega Patron

And what went wrong here: https://www.servicenow.com/community/developer-forum/how-to-convert-list-type-to-array-object-type-i...? It states you made it?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Daemon5
Tera Expert

I tried the script bellow and the Test result Output was comma separated ["undefined,undefined,undefined"] as shown in the attachment.
I also created a JSON Output "variables" to see inside the Input records, and was able to get the SysID of the record, so the problem is that I cannot get inside the String values(u_string1, u_string2, u_string3).

```
(function execute(inputs, outputs) {
outputs.array_test = [];
outputs.variable = [];
var record=inputs.records.split(',');

record.forEach(function(record) {
var string1 = record.u_string1;
var string2 = record.u_string2;
var string3 = record.u_string3;

var concatenatedString = string1 + "," + string2 + "," + string3;

outputs.array_test.push(concatenatedString);
outputs.variable.push(record);
});

})(inputs, outputs);
```