Summary

This article covers a script example to check absolute difference in time.

Table of Contents


Description

This script ensures that the absolute difference between 2 times cannot be greater than 5 minutes with ‘N/A’ being checked. The script uses the dateDiff command to calculate the difference in times and uses the abs command to get the absolute value of that difference. It then compares it to 5 minutes and then if it is greater than 5 minutes checks to make sure that ‘N/A’ is not checked. If it is, then it fires the alert. 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="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" when="preprocess" shouldReconcile='true'/>
    <dependent path="/summary/ecgReport[n].mncktime"/>
    <dependent path="/summary/ecgReport[n].crcktime"/>
</script>



Need more help?

Please visit the Fountayn Contact Information page.