{uccx scripting: holiday check via XML}

There are numerous Holiday check scripts out there for CCX; I saw one yesterday that comes with some scripts Cisco provides for free (or used to anyhow) and thought I’d write this post with a script that is quite the dichotomy from that particular script..Of course the objective is the same: Is Today a Holiday or Not?

Below is the Document we are going to parse..

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Holidays>
  <Holiday>1/1/14</Holiday>
  <Holiday>1/20/14</Holiday>
  <Holiday>2/17/14</Holiday>
  <Holiday>7/4/14</Holiday>
  <Holiday>9/1/14</Holiday>
  <Holiday>10/17/14</Holiday>
  <Holiday>11/27/14</Holiday>
  <Holiday>12/25/14</Holiday>
  <Holiday>1/1/15</Holiday>
</Holidays>

Let’s briefly go over some terminology when it comes to XML. Holidays is considered the Root of this Document; other ways in which to refer to an item in an XML file are: Element, Tag, Node. In fact every Element within an XML Document is considered a Node; you have the Elements

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Holidays><Holiday></Holiday></Holidays>

Holidays is the Root Node/Element of the Document..another way to say this is the Root Tag is Holidays and the child element (Tag) is Holiday each of these Elements can be referred to as XML Nodes as well..another XML Node is the Text Node values of the Holiday Elements: the Dates in “M/dd/yy” Format (Short). Ok..let’s break this down in the most simple term I possibly could; once I’m done I feel that you will get it!

//First We Have a String that will be converted to a
//(java.text.DateFormat.SHORT) style
//Cisco Set Step Follows:
Set todaysDate = new Date()
//Properties of this shows Short Date
//Download the Document, Setup for PARSING
//DOC is Store in DOC Repository
dHolidays = Create XML Document(DOC[Holidays.xml])
//The Parser is SAX (from the STD Java Library)
//Next we use the Get XML DOC Data
//To do this you have to use XPath
//holiday is a String type
holiday = Get XML Documnet Data(dHolidays,
     "//Holiday[.='" + todaysDate + "']")
//The Xpression above is 3 Strings
//Concat'd together
If(todaysDate == holiday) Then
    True
        Set isHoliday = true
    False
        //Today is Not a Holiday

Because there are multiple Holiday Nodes, in our XPath Expression we need to pass in a “String” Value that matches the Style in the Document (“M/dd/yy”) which essential returns the same text if that Date exists in the document; hopefully that makes sense..it is a weird looking “syntax” (better than descendant/child IMO) but if you read what XPath is, Wikipedia says it best:

XPath, the XML Path Language, is a query language
for selecting nodes from an XML document. In addition,
XPath may be used to compute values (e.g. strings, numbers,
or Boolean values) from the content of an XML document.
XPath was defined by the World Wide Web Consortium (W3C).

We are done..it can’t get much easier than that to check for a Holiday. I’m going to leave you with the Script and the DOC that I used in this Post. Most use HolidayChecks with SubFlow Steps in the Script..but why? In fact, why do we store the Holidays in an XML file to begin with; as a guy said it best to me the other day in the SupportForums, “this is how I was taught” and that voodoo is the hardest break…Open the script in the version of CCX you are running (it should work on 7.x and above)

HolidayCheckScript

Lastly I decided I would leave you with a video..this video depicts 2 Debug Sessions..1 where the Date Doesn’t Match Today (Not A Holiday) and 1 where I Manually Set Today’s Date to Holiday in the Document..so (isHoliday will equal TRUE)..If you want to watch the video in HD..then you’ll have to go over to the vimeo site and watch it there..And before I forget, here are the files I promised: HolidayCheck

return sam;

25 responses to “{uccx scripting: holiday check via XML}

  1. You wasted no time. Thanks

  2. Nice write up, and great to see a video is well. Only think for me was when in full screen the video was fuzzy
    Can ask what the app was that you where using to evaluate your xpath queries with?
    thanks again

    • Alexis, the tool is called Xmplify..and it runs on OS X..and costs $59USD..another one I’ve used is AquaPath (and it is $2.99USD in the App Store for OS X); it works pretty decently as well. I also wrote a short post on some of the tools I use for CCX development here..have a look. Just as an FYI, if you go directly to the Vimeo site where the Video is Hosted you should be able to watch it in HD..as unfortunately, the WordPress site doesn’t playback video in that manner. If this blog ever picks up any type of steam..I will eventually move it..

  3. I keep getting a “null” return value on the Set step for IsHoliday. I set my holiday for today and it blows right past the step to the False path.

    • Are you using Reactive Debugging? What does your Today Date look like (formatting)?

      • Yes using reactive debugging. He is what my Today Date formatting looks like:
        IF (todaysDate == holiday) Then
        True
        Set isHoliday = true
        Play Prompt
        Edn

        False
        Goto Hours (lable)

      • Did you update the XML file with the Date 11/11/2014?

      • Yes here is my file, minus the coding that goes at the top

        11/11/2014

      • Are you using my .aef file? the XPath expression is tricky in that when the String (todaysDate) is passed the formatting is (single quote)'”+var+”‘(single quote)..I don’t have a system to check this with..but if you haven’t already..you can watch the video..and I encourage you to go to vimeo and watch it in HD..

      • I think I might have found the error with the date it is populating as 11/11/14
        Not 11/11/2014

      • 11/11/14 is the proper way (that is what I meant at least) as this is the Short Date (Date Formatting) if you look at the Properties of todaysDate (set Step) you want to use a Short Date…

      • This seems to be my error this is what I have for my XML Path
        “//Holidays[.='” + todaysDate +”‘]”

      • Ok here is what I got when I just debugged again. I am missing something from this output but cant figure out what should belong there. It’s looking for the Holiday xml file but it is empty.

        doc_XMLHolidaysConfigDocument Document TEXT[
        \n 11/11/2014\n ]

        Where the “n” is at then a space the ConfigDocument did not work urghhh!

      • Ensure the Holiday.xml is formated Properly and Stored in the “Root” Directory of the UCCX Document Repository..I don’t think I discussed where to store the document..but if memory serves me correct(I don’t have a lab box currently..demo license expire way too fast)..

        I don’t even know what you are trying to do otherwise (with doc_XML…)..and the \n is just a NewLine Character..so if I have some sort of text like
        “happy\nbirthday” when you view it in a text file for instance it will look like:

        happy
        birthday

        The Date in the XML file should look something like this:
        <Holiday>11/11/14</Holiday>

      • HI Sam can you tell me what is in your Create XML Document Node??

        Thanks

      • I provided the documents at the end of the post; try to download the files HERE

  4. I’m not using your .aef file But yes you are correct it is in the XPath Epression

  5. Hi Sam ok I am going to view your video see if I can catch my mistake there. I am using the Short Date (Date Formatting)

  6. I put that in there as I use it for another step I do for checking for Emergency OpenClose

    I don’t even know what you are trying to do otherwise (with doc_XML…)..and the \n is just a NewLine Character..so

    So I used the above configuration because it was choking on Get XML Document reference

  7. Thank you so much for everything. I just started over from scratch and noticed I missed that there were double quotes and single quotes for the XPath. It’s working great now thank you.

      • Thank You again. Do you have any post or examples of scripts using the Get HTTP step? I need to be able to feed the caller inputted employee ID for example through a CTI URL interface which will in turn display to the agent receiving the call that callers information. If you have something in your repository that I could use for this please let me know.

        Thank You

      • When you make this HTTP Request..what do you get back in Response? XML Document etc. Oddly, I don’t have any example script where I’ve done this using the provided Script Steps..but I could help you figure it out for sure..Do you know how to make a “test” request from your web browser? Is there Authentication? Let me know.

  8. Hello Sam, Thank you very much for the post like this helping people to understand the scripting and more. I have been working on a holiday check script for a while now and having few difficulties. That could be because I am rookie in this field…I hope you can help me
    I am using your XML doc and your script to check for the holidays. The part I am getting confuse about-where exactly I need to go an apply this script to my main script? I have tried to apply it right after Accept step in my main one. Start->Accept->dholidays etc. I have also moved all the VAR from holiday to to my main script. Uploaded the xml doc to docmanagement on my uccx server with todays date a as holiday. When I call the script, it doesn’t redirect the call to voice mail number which I have selected in the step-if holiday==true call redirect to vm number!!!
    Any help would be greatly appreciated. Thanks

  9. well…it looks like I got everything working. I just want to thank you for this script and explanation.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s