I have a zap that gets a block of text. Within that block of text they are about 30 variables that I need to replace e.g.{{variable1}}, {{variable2}}, {{variable3}} etc.
I need to replace each of these variables with a different string that I get in another step of the zap.
Zapier has a tool called find and replace text which works well; however it only works for 1 string at a time so this would mean I would need to do this 30 times.
Is there a way to complete this is one or two steps. Is it possible to use Code by Zapier (either Python or JS) to achieve this?
Yep! This can be done very easily using a code step in Python:
You'll pass any data into the Code step in the input_data dict. I'm not sure how it's coming in or formatted, but hopefully you can build a dict out of it. I'll make one up in this example.
keys = input_data['keys'] # something like "{{a}},{{b}},{{c}}"
values = input_data['values'] # something like "1,2,3"
replacers = {k:v for k,v in zip(keys.split(','), values.split(','))} # makes a mapping like {"{{a}}": "1", ...}
str_to_replace = input_data['string_to_repalace']
for k, v in replacers.items():
str_to_replace = str_to_replace.replace(k, v)
return {'result': str_to_replace}
How exactly this fits your use case depends on how your variables and stuff come in, but it should get you most of the way there.
Related
I'm trying, to wrap my head around Touchosc and script based on LUA 5.1.
I have a number of labels, called song0, song1, song2, and so on. I'm trying to set different values in these, using
local text = 'Smoke On The Water'
for i = 1, 2 do
self.children.pager1.children.main.children.song[i].values.text = text
end
but that gives me an error.
:-) I do need help.
Finn
Since you haven't provided the actual error, it's difficult to say what the problem is, but if I have to venture a guess, then try replacing ...children.song[i].values... with ...children["song"..i].values.... Since there is no table song, you just need to generate dynamic field names.
This question already has an answer here:
Karate API Testing - Reusing variables in different scenarios in the same feature file
(1 answer)
Closed 1 year ago.
I am doing a test case where it will call API and that data will use next API call as part of One Scenario.
I am passing testdata as part of example 4 records .Here I have under one scenario first Given API call output passing to second given API call.As part of comapare the results i need the first API call output data to compare with second API call results.
So is there any way to capture all four test records data first API call data in one variable (each time variable to update)
example :
*def var = 'hello'
var = var +'world'
Please need help
Please read the docs, copied below for convenience: https://github.com/intuit/karate#script-structure
Variables set using def in the Background will be re-set before every Scenario. If you are looking for a way to do something only once per Feature, take a look at callonce. On the other hand, if you are expecting a variable in the Background to be modified by one Scenario so that later ones can see the updated value - that is not how you should think of them, and you should combine your 'flow' into one scenario. Keep in mind that you should be able to comment-out a Scenario or skip some via tags without impacting any others. Note that the parallel runner will run Scenario-s in parallel, which means they can run in any order.
So please don't expect a variable in one Scenario to be update-able by another Scenario.
But within a Scenario if you want to "collect" data, there are many ways. For example try appending to a list - refer: https://github.com/intuit/karate#json-transforms
* def init = []
# do some API call
* karate.appendTo(init, response)
Is it possible to access all the fields from a previous step as a collection like json rather than having to explicitly setting each one in the input data?
Hope the screenshot illustrates the idea:
https://www.screencast.com/t/TTSmUqz2auq
The idea is I have a step that lookup responses in a google form and I wish to parse the result to display all the Questions and Answer into an email.
Hope this is possible
Thanks
David here, from the Zapier Platform team. Unfortunately, what I believe you're describing right now isn't possible. Usually this works fine since users only map a few values. The worst case is when you want every value, which it sounds like you're facing. It would be cool to map all of them. I can pass that along to the team! In the meantime, you'll have to click everything you're going use in the code step.
If you really don't want to create a bunch of variables, but you could map them all into a single input and separate them with a separator like |, which (as long as it doesn't show up in the data), it's easy to split in the code step.
Hope that helps!
The simplest solution would be to create an additional field in the output object that is a JSON string of the output. In a Python code step, it would look like
import json
output = {'id': 123, 'hello': 'world'}
output['allfields'] = json.dumps(output)
or for returning a list
import json
output = [{'id': 123, 'hello': 'world'},{'id': 456, 'bye': 'world'}]
for x in output:
x['allfields'] = json.dumps(output[output.index(x)])
Now you have the individual value to use in steps as well as ALL the values to use in a code step (simply convert them from JSON). The same strategy holds for Javascript as well (I simply work in Python).
Zapier Result
Fields are accessible in an object called input_data by default. So a very simplistic way of grabbing a value (in Python) would be like:
my_variable = input_data['actual_field_name_from_previous_step']
This differs from explicitly naming the the field with Input Data (optional). Which as you know, is accessed like so:
my_variable = input['your_label_for_field_from_previous_step']
Here's the process description in Zapier docs.
Hope this helps.
In my forward method, I need to have a param that is list:
forward(params:[selectedLicences:[1,2,3]]],action...)
Currently, when the same parameters are submitted through a form, I access them like this:
List<Long> licenses = params.list("selectedLicences").collect{it as Long}
Is it possible to use the same code when forwarding, or I need to have code that will process the resulting String [1,2,3] and change it into a list?
I have seen one solution is to use the flash storage, but I am looking for other alternatives as well.
Could not find a way to do it, so I am forwarding a list, which turns to string, and then I parse it back to list on receiving controller.. I am not working with large data (usually 2-3 values) so performance is not an issue in this case..
I'm using SQL Server 2012, is there any possible way to get all the parameters of a stored procedure along with the values passed to it?
I need these things to build a xml. I mean this should happen in the procedure which being executed and it should be common for all the procedures.
For example, let us suppose we have to procedures,
uspSave, #name='test' #age=20
uspDelete #id=2
now in uspSave procedure, I need to get #name, #age and the values 'test', 20
and in uspDelete, I should get #id with value 2.
For getting the column names, I tried this,
select parameter_name
from information_schema.PARAMETERS
where specific_name = OBJECT_NAME(##procid)
now is it possible to loop through the result of above query and can we get the values.
I think your best bet would be to use some code generation to generate the code block you require.
i.e.
Create your sproc without the code to XML-ify the parameters
Knock up a quick script (could be done in TSQL) to then construct the sproc-specific block of TSQL to convert the parameters into XML, using INFORMATION_SCHEMA.PARAMETERS
Copy that bit of auto-generated script into your sproc
The way you were thinking with dynamic sql wouldn't work because of the scope - the parameters would not be accessible within that dynamically generated SQL, you'd need to pass them in as args via sp_executesql, which puts you back in square 1.
e.g.
DECLARE #someval int = 7
EXECUTE('SELECT #someval') -- #someval is not in scope
So, if it will help save time, then code gen looks like your best bet.