cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Compare/Count a field in a datapil to other records in the same datapil without looping?

johnw
Executive Chef I
Executive Chef I

I have an Epicor BAQ report I use in Workato that gives me a list of all SKUs in an order and their shipping information

99.9% of the time all the SKUs in an order will be on the same pricebook but on rare occasions 2 SKUs might on pricebook X and 1 SKU on pricebook Y so each record in the BAQ report will have a pricebook field 

is there a way in workato to count the number of different prciebooks or do i have to loop through each record to count them?

thanks

2 ACCEPTED SOLUTIONS

gary1
Executive Chef III
Executive Chef III

I don't know how your data is structured, but you can use a combination of pluck and uniq to accomplish what you need.

Here's how they work:

list = [
    {"book": "a"},
    {"book": "a"},
    {"book": "b"}
]

books = list.pluck("book") 
## outputs ["a","a","b"]

uniqbooks = list.pluck("book").uniq 
## outputs ["a","b"]

uniqbooks.size 
## outputs 2, the number of items in the array

 

View solution in original post

gary1
Executive Chef III
Executive Chef III

You can do it directly from the output of the Epicor action.

Also, just a heads up that will hopefully save you some time...

When you use .pluck you need to refer to a data pill by its "API key", which is the schema key and NOT it's readable label. This usually trips people up when using methods on connector data pills with really long labels, or when the label and the key are completely different.

To see the API key, just hover over the data pill. If you were to pluck the pill below, you would use .pluck("field_1") and not .pluck("blah blah blah...")

 

api key.jpg

I'm mentioning this because you might have to pluck "Price list 2 of price book ID 18 char c" and I would be very surprised if that label was also the API key.

 

View solution in original post

9 REPLIES 9

gary1
Executive Chef III
Executive Chef III

I don't know how your data is structured, but you can use a combination of pluck and uniq to accomplish what you need.

Here's how they work:

list = [
    {"book": "a"},
    {"book": "a"},
    {"book": "b"}
]

books = list.pluck("book") 
## outputs ["a","a","b"]

uniqbooks = list.pluck("book").uniq 
## outputs ["a","b"]

uniqbooks.size 
## outputs 2, the number of items in the array

 

johnw
Executive Chef I
Executive Chef I

this is cool... haven't played with Lists much in here.

So I created a List and loaded it with the field from the datapil which runs the BAQ report.

Do I need to create the list or is there a way to do these formulas directly from the data Pil; saving that one step? 

 

this works perfectly 

Pluck 1.png

โ€ƒ

se list formulas directly from the BAQ step or if I have to convert to a list first 

create list.png

gary1
Executive Chef III
Executive Chef III

You can do it directly from the output of the Epicor action.

Also, just a heads up that will hopefully save you some time...

When you use .pluck you need to refer to a data pill by its "API key", which is the schema key and NOT it's readable label. This usually trips people up when using methods on connector data pills with really long labels, or when the label and the key are completely different.

To see the API key, just hover over the data pill. If you were to pluck the pill below, you would use .pluck("field_1") and not .pluck("blah blah blah...")

 

api key.jpg

I'm mentioning this because you might have to pluck "Price list 2 of price book ID 18 char c" and I would be very surprised if that label was also the API key.

 

johnw
Executive Chef I
Executive Chef I

thanks, I was trying to use the output instead of the value which is why I couldn't get it to work ๐Ÿ™‚

pretty cool