Summary

This script checks that the given start date and time occur before the given end date and time. An alert will fire if it does not. The script first checks to make sure that all 4 questions are set. Then, the script has to concatenate the date and time questions (start date/time and stop date/time) and then uses the toDate command to convert it to a date.  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="stopBeforeStart"/>
    <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: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: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:gte>
                </s:or>
            </s:expression>
            <s:correction>
                <s:string value="optional"/>
            </s:correction>
            <s:text>
                <s:string value="Stop Date and Time is before the Start Date and Time. Please review and clarify."/>
            </s:text>
        </s:alert>
    </body>
    <target typeId="stoptm" when="preprocess" shouldReconcile='true'/>
    <dependent path="/form/path/goes/here.startdt"/>
    <dependent path="/form/path/goes/here.starttm"/>
    <dependent path="/form/path/goes/here.stopdt"/>
</script>



Need more help?

Please visit the Fountayn Contact Information page.