Summary
This article compiles a list of Scripts FAQ's.
Table of Contents
- I want to send out automatic emails if a condition is true however I want to send them out to seperate groups based on what server environment the user is on. How do I do this?
- What is "Staging"?
- How do I check the format of the user input?
- How do I determine if any dynamic forms have been inserted?
- When do I use a target versus a dependent to trigger a script?
- How do I get rid of form errors (errors that appear at the top of a dorm in the formEdit viewType)?
- How can I format emails sent from scripts?
- Why am I getting a generic format error with my script?
- I'm using the substr command and it is causing a "ClickOS" error or the generic error in Production or Approve. Why?
- How do I target a specific question alias when a questionType is re-used?
- Can relative paths be used in a script?
- How do I use merge?
- When do I use merge?
- Should merge always be used for commands where it is available?
- How to compare the partial date format "yyyy/MM[NK]/dd[NK]" with the original date format "yyyy/MM/dd"?
- What is an 'action' attribute for target and dependent paths? When and how do I use it?
- I have multiple scripts on a form. How do I ensure that one script is executed before another?
1. I want to send out automatic emails if a condition is true however I want to send them out to seperate groups based on what server environment the user is on. How do I do this?
Use the "environment" command to compare to a string of "Staging" or "Production" in order to find out which environment the script is running on.
<s:if> <s:eq> <s:environment/> <s:string value="Staging"/> </s:eq> <s:list> <s:string value="emailtriggers@datatrak.net"/> <s:string value="test1@clientAddress.net"/> </s:list> <s:list> <s:string value="emailtriggers@datatrak.net"/> <s:string value="test1@clientAddress.net"/> <s:string value="test2@clientAddress.net"/> <s:string value="test3@clientAddress.net"/> </s:list> </s:if>
2. What is "Staging"?
Staging includes Design, Test and the Approve environments. We do not currently differentiate between environments.
3. How do I check the format of the user input?
The easiest and fastest way to check the input format is by using the regular expressions.
<s:regex pattern="[0-3][0-9]-[A-Za-z]{3}-[2][0][0-9][0-9]"> <s:stringPath path=":value"/> </s:regex>
4. How do I determine if any dynamic forms have been inserted?
Count the number of forms using the "count" command:
<s:count> <s:parent> <s:form path="/aeSummary"/> </s:parent> </s:count>
5. When do I use a target versus a dependent to trigger a script?
A general rule of thumb is that dependents are only used in alert scripts. In those cases, the dependent path should be used on questions that should trigger the script but not show the alert.
6. How do I get rid of form errors (errors that appear at the top of a dorm in the formEdit viewType)?
In most cases, form errors are triggered when the script encounters a null or an incomplete value(a full date that is entered as a partial date). The best way to avoid the form errors is to do some basic error trapping at the beginning of the script.(checking for nulls, checking the length of input on dates, etc.).
7. How can I format emails sent from scripts?
We currently do not have a way to format emails that comes from scripts.
8. Why am I getting a generic format error with my script?
These are most often caused by a missing ":value" where you are trying to read the value of a question. You must specify the ":value" after a question or question path where you need to read the value out of that path.
9. I'm using the substr command and it is causing a "ClickOS" error or the generic error in Production or Approve. Why?
If you try to perform a "substr" action on a string that is not as big as length you are specifying, it will cause a fatal error. The way around this is to check the length of the string you are trying to grab the substring from before running the substring command:
- Note: In this example, the target of the script is the field we are looking for, so it is not necessary to provide the path to the question.
<s:if> <s:gte> <s:length> <s:value> <s:stringPath path=":value"/> </s:value> </s:length> <s:number value="7"/> </s:gte> <s:substr> <s:stringPath path=":value"/> <s:number value="0"/> <s:number value="7"/> </s:substr> </s:if>
10. How do I target a specific question alias when a questionType is re-used?
Use the id of the target question in comparison with the path to the question you are trying to trigger the script on:
<s:if> <s:eq> <s:numberPath path=":id"/> <s:numberPath path="/visit1/vitals.temp:id"/> </s:eq> </s:if>
11. Can relative paths be used in a script?
Yes, relative paths can be used for dependent questions on other forms or the same form, as well as for generation of forms. Forms can be generated under a relative path as well as a defined script path. Please reference the Using Commands DTLC page for more details on this functionality. For example:
Alert Script Example (Questions on the same form)
<script scriptId="absVal2"> <body> <s:alert> <s:expression> <s:or> <s:not> <s:isSet> <s:question> <s:question path=".mncktime"/> </s:question> </s:isSet> </s:not> <s:not> <s:isSet> <s:question> <s:question path=".crcktime"/> </s:question> </s:isSet> </s:not> <s:lte> <s:abs> <s:dateDiff unit="minute" method="integer"> <s:from> <s:datePath path=".mncktime:value"/> </s:from> <s:to> <s:datePath path=".crcktime:value"/> </s:to> </s:dateDiff> </s:abs> <s:number value="5"/> </s:lte> <s:not> <s:isSet> <s:question> <s:question path=".naadhu"/> </s:question> </s:isSet> </s:not> </s:or> </s:expression> <s:correction> <s:string value="optional"/> </s:correction> <s:text> <s:string value="The absolute difference between the 'ECG Monitor' and 'Control Room Clock' is greater than 5 minutes, yet 'N/A' is checked. Please verify."/> </s:text> </s:alert> </body> <target typeId="naadhu"/> <dependent path="/summary/ecgReport[n].mncktime"/> <dependent path="/summary/ecgReport[n].crcktime"/> <dependent path="/summary/ecgReport[n].naadhu"/> </script> Form Generation Script Example (Generation under a relative path) <script scriptId="create_fuv_dosForms"> <body> <s:if> <s:and> <s:isSet> <s:question> <s:question path=".thtxdat"/> </s:question> </s:isSet> <s:stringContains> <s:stringPath path=".:alias" /> <s:string value="_fuv" /> </s:stringContains> </s:and> <s:list> <s:createForm> <s:parent> <s:form path="../"/> </s:parent> <s:type> <s:string value="dospretxb"/> </s:type> <s:alias> <s:string value="dospretxb_fuv"/> </s:alias> </s:createForm> <s:createForm> <s:parent> <s:form path="../"/> </s:parent> <s:type> <s:string value="dospsttxb"/> </s:type> <s:alias> <s:string value="dospsttxb_fuv"/> </s:alias> </s:createForm> </s:list> </s:if> </body> <target action='update' shouldReconcile='true' typeId='thtx' when='after' /> </script>
12. How do I use merge?
- eq
- ne
- lt
- gt
- lte
- gte
- regex
- between
<s:eq merge="or"> <s:numberPath path=":id"/> <s:numberPath path="/AE_a_Summary/AE_a[n].AESTDT:id"/> </s:eq>
13. When do I use merge?
The merge option enhances our ability to compare values. When normally using an eq or a lt command you would compare two values, A vs. B. A merge makes it possible to compare many values in one step.
<s:eq merge="or"> <s:numberPath path=":id"/> <s:numberPath path="/AE_a_Summary/AE_a[n].AESTDT:id"/> </s:eq>
14. Should merge always be used for commands where it is available?
Only if you are comparing one value to many values or many values to many values. Then merge option is only needed when comparing a list. When comparing a list the system has multiple results and needs to know how you want them combined into a single result.
15. How to compare the partial date format "yyyy/MM[NK]/dd[NK]" with the original date format "yyyy/MM/dd"?
To compare the partial date format with the original date format:
- The format for the "toPartialDate" command is evaluated only when a string is specified as the first parameter. When a date question is passed as an example the format should be ignored
because the date question has its own format and it cannot have unknown days or months. - The "gt" command in this example will compare two partial date values and the usual partial date comparison behavior is applicable. When they are equal the two partial dates are also equal. The unknown date(NK/NK/NK) would be equal to any other date but it will never be greater than any other date.
- When the default comparison behavior for partial dates is not applicable, then the "adjust" attribute of the "toPartialDate" command can be used to adjust a partial date (having unknown fields) to the smallest possible value (min) or to the largest possible value (max).
Example:
- The default partial date logic will result in “equal” as the date could possibly be equal.
- If you adjust the partial date to “min”, then the adjusted partial date is lower than the real date.
- If you adjust the partial date to “max”, then the adjusted partial date is greater than the real date.
<s:gt> <s:toPartialDate adjust="min"> <s:datePath path="/someForm.partialDateQst:value" /> </s:toPartialDate> <s:toPartialDate> <s:datePath path="/someForm.dateQst:value"/> </s:toPartialDate> </s:gt>
Important: When you adjust a partial date to either "min" or "max" with the "toPartialDate" command, then you must use the "datePath" command and not the "partialDatePath" command.
16. What is an 'action' attribute for target and dependent paths? When and how do I use it?
Following is an example for target and dependent paths:
</body>
<target typeId="rate" action="update" when="preprocess"/>
<dependent path="/screening/dm.dob" action="update" when="after"/>
</script>
The action attribute tells the script which action should trigger the script. The possible options for the "action" attribute are:
- Update - This triggers the script to run whenever the target or dependent question/form is updated (saved).
- Create - This triggers the script to run whenever the target form is created (typically via the createForm command).
These actions can all be combined with the "when" attribute to determine if the script will run "preprocess" or "after" the action happens. So in our example above, the script will be triggered after the "rate" or "dob" questions are saved.
17. I have multiple scripts on a form. How do I ensure that one script is executed before another?
Scripts with when = "preprocess" (for example, alerts or simple calculations) will execute as soon as the necessary data is provided. However, any script with when = "after" (complex calculations, email notifications, form creation, etc) will execute upon form save. It is not possible to set the order in which those scripts will execute. This should be accounted for in the way your scripts are written. For example, Script A is responsible for calculating value A and assigning it to a field. Script B uses value A for further calculations. In this scenario, Script B should re-calculate the value and trigger the further calculations, rather than referencing the field assigned by Script A.
Need more help?
Please visit the Fountayn Contact Information page.