Summary

This article covers an example of a 24 hour duration script.

Table of Contents


The script reads a start date, start time, end date, and end time. If the start date and time is less than 24 hours before the end date and time, the alert is triggered. The script is first checking to make sure that all of the questions are set. Next, the script has to concatenate the date and time questions (for both the start and stop date/times) and then uses the toDate command to convert to a date. It passes one date to the “from” parameter and one to the “to” parameter of the dateDiff command to ensure that the difference between the start date/time and the end date/time is greater than or equal to 1440 mins (24 hours). Listing dependent question paths allow the script to trigger when a dependent variable existing on another form is updated with a new value.

Script

<script scriptId="duration24Hours">
    <body>
        <s:alert>
            <s:expression>
                <s:or>
                    <s:not>
                        <s:isSet>
                            <s:question>
                                <s:question path=".starttm"/>
                            </s:question>
                        </s:isSet>
                    </s:not>
                    <s:not>
                        <s:isSet>
                            <s:question>
                                <s:question path=".startdt"/>
                            </s:question>
                        </s:isSet>
                    </s:not>
                    <s:not>
                        <s:isSet>
                            <s:question>
                                <s:question path=".stoptm"/>
                            </s:question>
                        </s:isSet>
                    </s:not>
                    <s:not>
                        <s:isSet>
                            <s:question>
                                <s:question path=".stopdt"/>
                            </s:question>
                        </s:isSet>
                    </s:not>
                    <s:gte>
                        <s:dateDiff unit="minute" method="integer">
                            <s:from>
                                <s:toDate>
                                    <s:concat>
                                        <s:toString>
                                            <s:datePath type="date" path=".startdt:value"/>
                                            <s:string value="MM/dd/yyyy"/>
                                        </s:toString>
                                        <s:string value=" " />
                                        <s:toString>
                                            <s:datePath type="date" path=".starttm:value"/>
                                            <s:string value="HH:mm"/>
                                        </s:toString>
                                    </s:concat>
                                    <s:string value="MM/dd/yyyy HH:mm" />
                                </s:toDate>
                            </s:from>
                            <s:to>
                                <s:toDate>
                                    <s:concat>
                                        <s:toString>
                                            <s:datePath type="date" path=".stopdt:value"/>
                                            <s:string value="MM/dd/yyyy"/>
                                        </s:toString>
                                        <s:string value=" " />
                                        <s:toString>
                                            <s:datePath type="date" path=".stoptm:value"/>
                                            <s:string value="HH:mm"/>
                                        </s:toString>
                                    </s:concat>
                                    <s:string value="MM/dd/yyyy HH:mm" />
                                </s:toDate>
                            </s:to>
                        </s:dateDiff>
                        <s:number value="1440"/>
                    </s:gte>
                </s:or>
            </s:expression>
            <s:correction>
                <s:string value="optional"/>
            </s:correction>
            <s:text>
                <s:string value="The duration is less than 24 Hours. Please review and clarify."/>
            </s:text>
        </s:alert>
    </body>
    <target typeId="stoptm" when="preprocess" shouldReconcile='true'/>
    <dependent path="/form/path/goes/here.starttm"/> 
    <dependent path="/form/path/goes/here.startdt"/>
    <dependent path="/form/path/goes/here.stopdt"/>
</script>


Need more help?

Please visit the Fountayn Contact Information page.