Help

Re: Automation - Get input variable as JSON

Solved
Jump to Solution
2157 0
cancel
Showing results for 
Search instead for 
Did you mean: 
LucasT
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi everyone,

I'm trying to do a multi-step automation, where I :

  • find records (questionnaires) using the "Find records" step*
  • feed the records I found as "input variable" to a script
  • use that script to compute values, based on the field "grade" of each "questionnaire" in my "questionnaires" list

My problem :

  • When I try to use the input as "list of record", the input is in fact an HTML string with which it's hard to work :
  • LucasT_0-1686661060039.png

     

  • console.log(questionnaires) => LucasT_1-1686661397457.png
  • And it's the same if my input variable is a "grid", the only other option available.

Is there a way I could get a nice, clean JSON as in input instead of this nightmare ?

Thanks 🙏 

 

* I do this instead of scripting my query because the database is huge, and I get out of memory errors when I try script it

1 Solution

Accepted Solutions

Hi,
use 

Alexey_Gusev_0-1686717205186.png

 

Alexey_Gusev_1-1686717234984.png


then in code loop both arrays using index parameter
like this

Alexey_Gusev_2-1686717769045.png

 

See Solution in Thread

4 Replies 4
LucasT
5 - Automation Enthusiast
5 - Automation Enthusiast

Edit :

I solved it (thanks to chatGPT <3) this way :

var myList= [];


  const refRegex = /<b>Ref<\/b><br\/>(.*?)<br\/><br\/><br\/>/g;
  const gradeRegex = /<b>Grade between 0 to 10<\/b><br\/>(.*?)<br\/><br\/><br\/><span style="display:inline-block;height:1px;width:100%;background-color:#999"> <\/span><br\/>/g;

  let refMatch;
  let gradeMatch;

  while ((refMatch = refRegex.exec(questionnairesHTML)) !== null) {
    const ref = refMatch[1].trim();

    if ((gradeMatch = gradeRegex.exec(questionnairesHTML)) !== null) {
      const grade = parseInt(gradeMatch[1].trim(), 10);

      myList.push({ "Ref": ref, "Grade": grade });
    }
  }

However, it's quite dirty and not resilient (if someone changes the background color of the field, the regex will break ...), so if anyone has a better way I'd love to hear it !

 

You cannot get clean json directly from a Find Records action.

Can you process each record individually or do you need to process the records as a set?

If you can process each record individually, you can use a repeating group. Then use input variables for each individual record.

If you need to process the records as a set, have your input variable be a list of record IDs from the found records. Then have your script query for the records to read the values from the queried records.

Hi,
use 

Alexey_Gusev_0-1686717205186.png

 

Alexey_Gusev_1-1686717234984.png


then in code loop both arrays using index parameter
like this

Alexey_Gusev_2-1686717769045.png

 

It's a great workaround, thanks !