Javascript/Calculate field - helpful syntax

Show/hide fields
 
Hide fields
 
if([csField]=="yes")
    {
         suppressFields
              ('[otherCSField]');
     }
        
Show Fields
 
if([csField]=="yes")
            {
                showFields
                ('[otherCSField]');
              }
            
Working with dates
 
Working with dates/times can occasionally be confusing, depending on what you want to achieve, there a few different methods we'd recommend to use, that we've found work best. 
 
Scenario 1 - You have a script that needs an outbound call made to a head office during working hours, but require an engineer to be called out of hours. 
 
var d = new Date();
var n = d.getHours(); 
var s = d.getDay();
if (s == 6 || s == 0 || n >= 17 || n < 9)
    {
   suppressFields('[OH]');
   showFields('[OOH]');
    }
else 
    { 
   suppressFields('[OOH]');
   showFields('[OH]');
    }
 
We set a few variables (d, n & s) to their relevant date functions, and utilize the Day function to determine if the day is Saturday or Sunday s == 6(Saturday) or s == 0(Sunday), or the hour is >= 17 or < 9. As we've used an or operator '||', not an and operator '&&', if any of these functions are true, the field '[OH]' will be suppressed, and the field '[OOH]' will remain visible. There's not limit to the amount of fields that can be suppressed or shown, so entire fields like table controls containing engineer details can be hidden or shown when needed.
 
Scenario 2 - A date needs to be entered in script, and you need to ensure agents are NOT selecting a date in the past. 
 
The below Syntax requires a basic script to see it's functionality, with a date field and two text labels, one named [past] and another named [future].
 
var date = Date.parse([Date Field]);               //Inserts the string and returns as MS. Ensure ISO standard of date format is used (yyyy-mm-dd)
 
var d = new Date();
var cuDate = d.getTime();          //Gets the current date in MS
 
suppressFields('[past]', '[future]');
 
if(date <= cuDate){
    showFields
        ('[past]');                  //insert any functionality of choosing
else if(date > cuDate){
    showFields
        ('[future]');               //insert any functionality of choosing
}
    
    Ensure you set the date format to yyyy-mm-dd(ISO standard), to make sure the correct function is seen.
 
The first part of the code block gets the date field as an ISO format date string, and converts it into the amount of milliseconds from  midnight of Jan 01 1979.
By using milliseconds, we remove the need to compare days in months, which can become confusing. 
The next two lines get the current date in milliseconds from midnight Jan 01 1979, for comparison.
 
In this example, the two text labels are suppressed, and depending on whether or not date (amount of milliseconds between the selected date and 01/01/1979) is smaller than, or equal to cuDate (amount of milliseconds between the current date and 01/01/1979). If the amount is less, the date is in the past, so the test label past will be displayed, if not, future is displayed.
 
 
Displaying previous call details in script (Helpful when utilizing task management)
 
 
[var_URL] = '/CampaignManagement/CallManager/CallDetails.aspx?num=1&sessionid=' + [var_csMQReference];
 
    1. Apply this code to a calculate field in the task management page of the script that the agent will use to action the call after it has been taken.
    2. Create a hidden field named 'RunOnce'
    3. Add the following code underneath the existing code in the calculate field.
 
        
if([RunOnce]=="")
{
[RunOnce]='CalcFired';
openPageFrameset([var_URL],'script.aspx?step=25881');
}
 
    4. Or if you would like to display information/instructions on on half of the page, and the call details on the other, insert the following code instead. Make note of the section that will fire the instruction to display side by side - 'parent.webFrameSetSideBySide='true';'
 
if([RunOnce]=="")
{
[RunOnce]='CalcFired';
parent.webFrameSetSideBySide='true';
openPageFrameset([var_URL],'script.aspx?step=25881');
}