Tuesday 2 July 2013

UCCX Script for passing timezone as a parameter

Recently faced a requirement from one of our client to implement script for there different location which are in different timezone in in the same time to check the Working hour and weekdays.

After doing some research in the internet came across few valuable post but the one that i found will fulfill my requirement is from Johnathan in cisco support forum

In my script i have used the same one as a subflow for many of the subflow that  i have used in the main script.

That script will used predefined java classes   and fetch the data from the calender value in java

We defined a  a string value called currentTime as a string  and from the below code pass the value of the java script to currentTime and then change the current time to integer value as below .


Below script can be user to get the time and change the time zone based on the parameter of a string variable called timeZone :

You can use the set step to define the return value to currentTime (an integret variable defined in the script)

{
    //Initialize variables
    String strHourOfDay = "";
    String strMinute = "";
    String strSecond = "";
    //Set the time from local values
    java.util.Calendar callCalendar = new java.util.GregorianCalendar();
    int intHourOfDay = callCalendar.get(java.util.Calendar.HOUR_OF_DAY);
    int intMinute = callCalendar.get(java.util.Calendar.MINUTE);
    int intSecond = callCalendar.get(java.util.Calendar.SECOND);
    //Adjust to the timezone if specified
    if((timeZone != null) && (timeZone.length() >= 1))
    {
        callCalendar = new java.util.GregorianCalendar(java.util.TimeZone.getTimeZone( timeZone ));
        //Update the time for the timezone
        intHourOfDay = callCalendar.get(java.util.Calendar.HOUR_OF_DAY);
        intMinute = callCalendar.get(java.util.Calendar.MINUTE);
        intSecond = callCalendar.get(java.util.Calendar.SECOND);
    }
 
       if (intHourOfDay < 10)
                strHourOfDay  =  "0" + intHourOfDay;
    else
                strHourOfDay = "" + intHourOfDay;

    if (intMinute < 10)
                strMinute = "0" + intMinute;
    else
                strMinute = "" + intMinute;
      if (intSecond < 10)
                strSecond  =  "0" + intSecond;
    else
                strSecond = "" + intSecond;
    //STOP changing to string values

    //Return the time in a custom formatted form
    return strHourOfDay + strMinute + strSecond;
}

The current timeZone(string varaible) value  can be assigned from its preceding script using the subflow step and pass into this script.

and you can pass the time returned in the variable currentTimeint  to the preceeding call flow  and preeceding call flow can be can use this varaible to check the value with some predefined  integer variable passed as parameter in format hhmmss  and use an if statement to chenage boolean variable to change in true or flase based on working hour or not


I used it in my lab and  seesms to be good....

No comments:

Post a Comment