Important Update to Custom Scripting
The CustomScript Action now supports the LUA programming language. Visit our NEW Lua Scripting Resources!
- New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
- As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
- In the long term, Legacy Custom Scripting Actions will be switched to read-only. The exact date on this is to be determined; we will send notifications well ahead of time.
Did you know that you can use the question Alias in place of question ID almost universally in scripting and merge codes?
Why aliases are much better to use in scripts
- You can use aliases in your script that mean something.
- Your scripts can be re-used more easily across surveys. Question IDs change, aliases do not!
- Your code will be more readable!
- Your merge codes will be more readable!
Here's how it works
In the Alias field on the Logic tab of the question editor, enter whatever you want your variable name to be. Then simply reference this alias in place of the Question ID in your scripting.
For example, say you have 3 number validated questions that ask "How tall is the box in feet?", "How wide is the box in feet?" and "How deep is the box feet?" The question IDs are 2, 3, and 4 respectively.
The script to calculate the volume would be:
%%volume = sgapiGetValue(2) * sgapiGetValue(3) * sgapiGetValue(4);
Seems easy enough yes? Well, if you've done a little scripting within Alchemer, you know that it is tough to reuse this script in a new survey. The likelihood that the question IDs will be the same in the next survey you build are pretty low. So, reusing scripts usually requires manually updating the IDs in order for it to work in a new survey.
If you use aliases instead, reusing the script is a cinch! It's also easier to read!
For example, take the same questions above and assign the aliases "height", "width", and "depth."
Now the script to calculate the volume would look like so:
%%volume = sgapiGetValue("width") * sgapiGetValue("height") * sgapiGetValue("depth");
Did you know merge codes also work this way?
YEP! That's right!
Scripting and Other Out-of-the-Box Customizations
We’re always happy to help you debug any documented script. That said, we do not have the resources to write scripts on demand.
If you have customization ideas that you haven't figured out how to tackle, we're happy to be a sounding board for Alchemer features and functionality ideas that might meet your customization. Beyond this, you might want to consult with someone on our Programming Services Team; these folks might have the scripting chops to help you to achieve what you are looking for!