- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 02:08 AM
Hi
I have created a custom action using the Flow Designer on my instance. I have used the Look Up Record(s) action to retrieve the list of records from the conditions that i have given. On next step i need those records from the 1st step to be ingested into 2nd step which is a Script Step.
For. eg I have 3 records as output from the Look up Records action and iterating the 3 records with a loop condition. Here I cannot fetch the specific fields from the output of the 1st record. The output records has data with integer, string and duration data type. u_corporate_account is the field that is present in the output.
(function execute(inputs, outputs) {
var inputArray = inputs.lookupRecords; -------> Ingesting input records from the Lookup action
var corpName= inputs.currentAlertCorpName;
var resultant = [];
outputs.debugstr="go-";
for (var value in inputArray){
var corporate_account = value.u_corporate_account;
outputs.debugstr+="corp_account is "+corporate_account+" \n"; -------> here received "Undefined" as output
if(corpName.startsWith(corporate_account)){
resultant.push(inputArray[value]);
}
}
})(inputs, outputs);
This is a piece of code that i used to debug. Can anyone help me how to fetch fields from the output records of the Look up Records step through the script.
Solved! Go to Solution.
- Labels:
-
Script Debugger
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 02:52 AM
Hi,
try this
you can iterate over using .next()
(function execute(inputs, outputs) {
var inputArray = inputs.lookupRecords.records;
var corpName= inputs.currentAlertCorpName;
var resultant = [];
outputs.debugstr="go-";
while(inputArray.next()){
var corporate_account = inputArray.u_corporate_account;
outputs.debugstr+="corp_account is "+corporate_account+" \n";
if(corpName.startsWith(corporate_account)){
resultant.push(inputArray);
}
}
})(inputs, outputs);
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 03:25 AM
this one
How to loop through Flow Designer step result list in a script
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 03:36 AM
Hi,
I was able to achieve as per docs
For your custom Action your input variable should be of Type
Records.<Your Table Name>
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 03:50 AM
I was able to get the field value. Just now tried using this script
(function execute(inputs, outputs) {
// ... code ...
var inputArray = inputs.lookupRecords;
var corpName= inputs.currentAlertCorpName;
var resultant = [];
outputs.debugstr="";
while(inputArray.next()){
//for (var value in inputArray){
var corporate_account = inputArray.u_corporate_account;
outputs.debugstr+="corp account is"+corporate_account";
}
})(inputs, outputs);
Output:
corp account is XYZ
After the changing the iteration method i was able to achieve this
Thanks for your help Ankur.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 03:59 AM
Please mark my response as correct and close the thread.
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā03-19-2021 03:28 AM
Hi,
there is an example on docs for the same
Create a custom action to generate an array of objects from a list of records
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader