Question

Line items with two different values ("0" and "1")


Userlevel 1

Hello!

Is it possible to define which value to use from when there is more than one value?
I’d like to extract the ‘0’ and ‘1’ value seperately.
Somehing like {{...__line_items[]properties[Property 1 here]value}}.

 

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

7 replies

Userlevel 7
Badge +7

Hi @AdBuilder ,

 

Could you explain your challenge a bit more detailed? Maybe with some example? This way we can understand it better. 
I am not sure if I understand your question, but maybe you can use an action “Formatter by Zapier” to format the output in some sort of input you want to have.

Let me know!

~Bjorn

Userlevel 1

Hi Bjorn

 

Thank you for taking your time to understand my issue.

I am trying to extract some data from Shopify. Problem is that it combines two sets of data into one. 
So when I add the line item I get both the value of properties 0 and 1 combined. I can however split the text and get the URLs extracted. But I have no clue how to extract the value from properties 1 only. I thought there were some way I could define zapier to only read line item - properties - 1 - value.

This is the data I get in from Shopify:

 

line_items

   0:

        properties

            0:

               name: Link til bolig

               value: https://www.realmaeglerne.dk/bolig/4911278-brunebjerg-17

            1

               name: Vælg indhold

               value: 1. Kort, 3. Kontakt- & boliginfo

 

    1:

           properties

               0:

                   name: Link til bolig

                   value: https://www.realmaeglerne.dk/bolig/529-1306-koldinghuse-nord-2

               1:

                   name: Vælg indhold

                   value: 1. Kort

 

This is the data I get out:

 

Line 1: “https://www.realmaeglerne.dk/bolig/4911278-brunebjerg-17,1. Kort, 3. Kontakt- & boliginfo”

Line 2: “https://www.realmaeglerne.dk/bolig/529-1306-koldinghuse-nord-2,1. Kort”

 

This Is how I would like it

(Properties 0 value)

Line 1: “https://www.realmaeglerne.dk/bolig/4911278-brunebjerg-17”

Line 2 “https://www.realmaeglerne.dk/bolig/529-1306-koldinghuse-nord-2”

 

(Properties 1 value)

Line 1: “Kort, 3. Kontakt- & boliginfo”

Line 2: “1. Kort”

 

Hope it made sense even though I’m pretty new to zapier.

Userlevel 7
Badge +7

Thanks for the explanation @AdBuilder . I understand your question.
The challenge you have here is a bit difficult. You are getting the values of your properties in different objects (0 and 1) and from both objects you want to retrieve a value again with the same key.

This will probably require some code which I can’t provide to you on the spot. I will try out some stuff, but in the meantime let’s see if @ikbelkirasan has got some input here.

Let me know if you figured out something yourself.
~Bjorn

Userlevel 1

@ForYourIT  I’ve tried playing a bit around with formatting, but without luck. 

Please write if any proposals for Zapier comes to your mind. Because I’m out of ideas.

 

Userlevel 7
Badge +12

Hi @ForYourIT  and @AdBuilder,

Ok, let me try to solve this problem. In a Code step with the following code snippet, add a new input field called raw and its value should be in this format {{86783928__line_items}} where 86783928 is the previous step ID and line_items is where the line items are stored.

const lineItems = [];

const lines = inputData.raw
.replace(/\n{2,}/g, "\n")
.replace(/^properties: /gm, "")
.replace(/'/g, '"')
.split("\n")
.map(JSON.parse)
.map((line) => line.map((it) => it.value))
.forEach((line) => {
line.forEach((item, i) => {
lineItems[i] = lineItems[i] || [];
lineItems[i].push(item);
});
});

output = [{ lineItems }];

The output should look like this:

I hope this helps.

Userlevel 1

Thank you so much @ikbelkirasan 
I’m getting this error: Traceback (most recent call last): SyntaxError: invalid syntax (<string>, line 8).

And to be honest I have no clue what I’m doing. I can see that you offer a service helping out with these things, so maybe you could invoice me and help me in the specific zap?

Userlevel 7
Badge +12

@AdBuilder - Sure, check your inbox!