Store Sets of Data for Loop

I am a begginer and want to know if I am doing a correct way or not.

I have a few sets of URL lists.

Original URL ( only 1 URL )
and target URLs ( it can be 1~5 URLs )

I am basically copy some content from the Original URL to 1~5 target URL ( pages ).

I have these as a set ( multiple original URL (including targets) ). So I need a loop.

I just created 1 set Macros to store the URLs.

========= My Step ==========

  1. Get the original URL by Google script. ( document.querySelectorAll('.Link_orginal .value')[0].innerText; )
  2. Save to variable: Original_URL

  1. Get each target URL by Google script. ( document.querySelectorAll('.Link_links .value')[0].innerText;

  2. Save to variable : Target_URLs

Repeated 5 times. intLoop and +1

The result looks like this.
image

image

I was wondering if these are a correct way to do.
If you have another idea or better one, please let me know.
I am wondering if using variables is correct way or I should use array or json.
I need multiple sets of URLs ( original URL including its target URLs ).

And I will make another loops to run another Macro actions

As you may know, I am a beginner in KM and JS as well. I found there are many features in KM and wants to know if mine is correct.

Thank you for reading and your time. :slight_smile:

Additionally, I tried ( tested ) json data and loop.

Set a json data.

and made a loop with for each.

But it doesn't work. for each loop seems to not working.
Can you please have a look and let us know what's the problem?

Thanks,

Hey @apple_sasi,

On balance your macro looks fine. I would probably change is the Repeat action to a For Each action with the Lines-In-Collection option:

image

That saves you from having to explicitly manage the number of iterations.

-Chris

1 Like

Thanks Chris.

Yes, it works to get each line.
the result is
"["
"{"
... etc.

But I need to get the json data. Orginal URL and target URLs
And loop multiple times. ( the target url amout )

Thank you anyway :slight_smile:

The point was that you don't need to store items as JSON data.

You can use a flat list.

-Chris

1 Like

Hi, Chris :slight_smile:

Then how I can get the original URL and also target URLs.

image

The set (list) of URL needs to get the original URL and target URLs ... and then loop.

Thank you,

I think I got it. : :smiley:

  1. Set a sample data and added a temp end string "DONE".

  2. Set Loop 0 and when K value is "DONE" and the loop sets 0.
    if loop is 0, then it's the original URL and is not, then target URLs.

So far, it works fine. :smiley:

If you have time, plz have a look and see if I understood correctly.

Thank you for ur time again!!

It looks more or less like what I had in mind, and is much easier in this context than dealing with JSON.

-Chris

1 Like

Hey Chris,

It's seems @apple_sasi is coming in hot while throwing fast balls. Sheesh! :flushed:

KC

2 Likes

Learned from @ccstone and others. :smiley: Thank you all.

2 Likes