Hi, I'm trying to build a Zap that get's a response from an API from Booqable and creates a task in Asana. I have the response as a value that it's something like this: "4x4 Carbon Fiber Matte Box, Subloc filtro x, subloc bbbb"
And I would like to pass to the next action only strings between commas that have "Subloc" in it (ignoring case). I've tried many things and got some regular expression: (?<=,),^,]*((?i)Subloco^,]*)(?=,)*. In every place it returns correctly, but on zapier I got outputs blanks. I've also tried to "Line-item to text" or "pick from list" inside the format utilities without avail. Is there a better way to get those two items between commas containing "Subloc" (or "subloc") and pass both (separately) to the next action (create task in asana). Thank you very much
Thank you very much @Troy Tessalone. What I can't get around my head is that the response is already separate but in the next action only let me select this line with commas (that does not exist on the json response). The response should (at least when send a get commando for this endpoint in other places) is like this:
And on the next step the only option I have that contains these mentions is:
So appears to be flatten. Maybe I'm missing something or I'm complicating things. Thanks
Maybe something like this:
?
Actually looking closely, the last post refers to a json that have fields separated that's not my case. I just want to parse all itens inside Order > lines > title that contains "Subloc" (or subloc).
Thanks
@Lucas Saldanha
You can use this data point as an input for the Code step to then split based on commas to create line items.
Thank you. I've tried, but only returns one item. Programming is not a strong suit for me :( Maybe have to do a "for each" or something like that? This is what I'm using:
let Content = inputData.Content; let sublocitem = Content.split("Subloc"))1].split(","))0].trim();
output = {sublocitem}];
There's no way of zapier to pass individual items to the next step without the need to do a script? Thank you very much
Hi @Lucas Saldanha Yes, what Troy is suggesting would be to use something like a forEach to filter out line items that don’t have “Subloc” in them. Zapier collapses line item data (by like keys) so that is what you are experiencing. Zapier is taking the Order Lines array and collapsing the objects by their keys so you end up with Order Lines Title which has the values of all the line item titles separated by commas.
Code would be the most efficient way to only send the titles you are interested in.
//assumed that your titles are in a field 'Content' let Content = inputData.Content;
//split the text field back into an array, splitting at every comma //note this can have negative effects if any of your titles have commas in them.
let sublocitems = Content.split(",");
let individualObjects = {};
sublocitems.forEach((item,index) => {
//check if the item has the word "Subloc" in it if (item.toLowerCase().includes("subloc")) { individualObjectsa`item ${index}`] = item; } })
return individualObjects
OUTPUT:
@GetUWired thank you very much, this is perfect! One more detail if possible: if I would like to get Subloc and subloc (ignoring case sensitiviy), how would I change the code?
Thank you very much,
Best Regards,
Hi @GetUWired how is everything? One more question. Since I'm using a code to split the items, on the next step would be to create tasks.
But I can only choose one "field" on the task (referencing 1 item only). And I would like to create 2 tasks if it has 2 items, 3 if it has 2, 5 if it has 5 and 1 if only have 1.
I've looked into the looping by Zapier but couldn't find anything to work with. Best Regards
Hi Lucas!
Sorry for just now getting back to you!
I will answer your questions in order..
First, the code is not case sensitive “subloc”, “SUBLOC”,”Subloc” or any other combination would all match. Thats what the item.toLowerCase() part of the code does.
Second, the code currently just outputs all items as individual indexed items.. There are a couple of ways you could modify the code to run a loop. The easiest of which would just be to have the code return a list of objects (Zapier will then enter into a loop for each object returned). In testing, it will look as though there is only 1 item found.
//assumed that your titles are in a field 'Content' let Content = inputData.Content;
//split the text field back into an array, splitting at every comma //note this can have negative effects if any of your titles have commas in them.
let sublocitems = Content.split(",");
let individualObjects = {}; let allSublocItems = a];
//check if the item has the word "Subloc" in it if (item.toLowerCase().includes("subloc")) { individualObjectsi'item'] = item; individualObjectsi'loop index'] = index allSublocItems.push(individualObjects) } })
return allSublocItems
Given the additional details, it sounds like another way you could have accomplished this without code would have been to use Looping By Zapier in place of the code block, and then inside of the loop, you would put a filter step to only continue if the item name contains ‘subloc’.
Thanks a lot @GetUWired! I'll test here. Best Regards,