Increment a value in an Attribute

(Biewl Henrique) #1

Hello guys!

I need help again!

I set a “Make HTTP request” and i need put the values in a Google Sheet.
Exemple: Trigger > HTTP Request (many results; get many values in a Tag) > Label > Add a Row ({{HTTP Request.data__GRIEVOUS__+n__player}} > GoTo Label

Data
{
“GRIEVOUS”: [
{
“gear_level”: 1,
“power”: 1014,
“level”: 1,
“url”: “/u/seamos/collection/”,
“combat_type”: 1,
“rarity”: 4,
“player”: “Seamos”
},
{
“gear_level”: 1,
“power”: 1014,
“level”: 1,
“url”: “/u/humilde/collection/”,
“combat_type”: 1,
“rarity”: 4,
“player”: “Humilde”
}…

So I need help with that. I can not increment the value “+ n” until I finish reading all the values.
I know it exist the * and && for reading all the values, but, with this, “Add Row” put in the same row all the values…

Someone can help me?

(Daniel Beckett) #2

Hi @BiewlHenrique

Unfortunately you can’t increment the value inside the output as attributes/variables can’t be used for Data Outputs. If you always have a set number of results returned , i.e. 10 items returned you could still setup a flow to make this work by using Filters.

e.g.
Add a Row {{HTTP Request.data__GRIEVOUS__1__player}}
Add a Row {{HTTP Request.data__GRIEVOUS__2__player}}
Add a Row {{HTTP Request.data__GRIEVOUS__3__player}}
Add a Row {{HTTP Request.data__GRIEVOUS__4__player}}
etc.

(Biewl Henrique) #3

Hey @DanielBeckett, thx for answer!

I got it. I’ll need change my logic then. My problem is that number of results never the same.

Thx for now!

#4

Hi @BiewlHenrique,

you have 2 point: to loop, and to know loop is ended.

We have two features to help us: Code and Label metadata.

1)

after Label create a Code named Get Players with an inputs index with value {{your-label-action-name.metadata__index}} in code put this:

var records = {{your-wp-webhook-action-name.data__GRIEVOUS}};
var index = 0;
var player = {"name": "", "next": 0};

if (inputs.index.length) {
  index = parseInt(inputs.index);
}

if (records.length != 0 && records.length > index) {
  player.name = records[index].player;
  player.next = index +1;
}

resolve(player);

2)

Add a filter to Add a Row {{get_players.result__name}} is not empty

3)

Modify Goto Label:
a) Add a metadata named index with value {{get_players.result__next}}
b) Add a filter {{get_players.result__next}} does not equal 0

4)

Your add row becomes Add a Row ({{get_players.result__name}}

1 Like
(Biewl Henrique) #5

@CaosMkt, I don’t have words to thank you!

Even without knowing much, I made some changes according to what I needed.

1)

var records = {{swgoh.data__GRIEVOUS}};
var index = 0;
var player = {"nick": "","gear": "","pow": "","lvl": "","link": "","ctype": "","rar": "", "next": 0};

if (inputs.index.length) {
  index = parseInt(inputs.index);
}

if (records.length != 0 && records.length > index) {
  player.gear = records[index].gear_level;
  player.pow = records[index].power;
  player.lvl = records[index].level;
  player.link = records[index].url;
  player.ctype = records[index].combat_type;
  player.rar = records[index].rarity;
  player.nick = records[index].player;
  player.next = index +1;
}

resolve(player);   

I don’t know that code is right, but work perfectly to me!

What I need now is set a variable in swgoh.data__GRIEVOUS because this value change.
I would need read all this “API” - https://swgoh.gg/api/guilds/7545/units/ and get all the values after the Data separating by the tag.

I hope that I explained right! And sorry for my English. I’m study yet!

#6

Great job @BiewlHenrique, don’t worry for your english mine is not better your :yum:

You need some change:

1)

you need an array with your tag names.
Create a new code action before label, call it Get Tags :

var tags = {{swgoh.data}};
var tagName;
var tagsNames = [];
    
for (tagName in tags) {
  tagsNames.push(tagName);
}

resolve(tagsNames); 

2)

change first action code adding a new input indexTag with value {{your-label-action-name.metadata__indexTag}}

var tags = {{swgoh.data}};
var tagNames = {{get_tags.result}};
var indexTag = 0;
var player = {"nick": "", "tag": "", "gear": 0, "pow": 0, "lvl": 0, "link": "", "ctype": 0, "rar": 0, "next": 0};

if (inputs.indexTag.length) {
  indexTag = parseInt(inputs.indexTag);
}

if (tagNames.length != 0 && tagNames.length > indexTag) {
  var tagName = tagNames[indexTag];
  var records = tags[tagName];
  var index = 0;

  if (inputs.index.length) {
    index = parseInt(inputs.index);
  }

  if (records.length != 0 && records.length > index) {
    player.tag = tagName;
    player.gear = records[index].gear_level;
    player.pow = records[index].power;
    player.lvl = records[index].level;
    player.link = records[index].url;
    player.ctype = records[index].combat_type;
    player.rar = records[index].rarity;
    player.nick = records[index].player;

    if (records.length == index +1) {
      // last player of tag, set next tag index
      player.next = 0;
      player.nextTag = indexTag +1;
    } else {
      // continue looping on tag players
      player.next = index +1;
      player.nextTag = indexTag;
    }
  }
}  

resolve(player);

3)

add a new metadata to Goto Label named indexTag with value {{get_players.result__nextTag}}
change filter to {{get_players.result__nick}} is not empty

WARNING

“As a precaution against infinite loops, the Goto a Label action may be used 20 times (in total) during the course of a flow.” https://support.flowxo.com/article/151-flow

1 Like
(Biewl Henrique) #7

When we solved a problem, appear other rsrs

If the maximum number of the loops the Goto a Label is 20 times, this is don’t work.
You know if have the some solution for this?