" /> GVP 7.6 How to code to compare variables - Genesys CTI User Forum

Author Topic: GVP 7.6 How to code to compare variables  (Read 7393 times)

Offline rlcrockett

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
GVP 7.6 How to code to compare variables
« on: February 21, 2009, 07:23:29 PM »
Advertisement
I am use to IVR platform editors that offer the ability to build complex formulas or do compares, but I don't see any of that in Studio.  Can someone give me an example, I assume it would be have to be executed in a Code block, of how to compare two dates.

Offline Infinity

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: GVP 7.6 How to code to compare variables
« Reply #1 on: February 23, 2009, 02:20:21 PM »
I apologize first hand if haven't understood your question clearly. Is your question "how to compare two dates?" or "how to write code in the code block?". I can give a jsp(Java) example(The script-type is set to VoiceXML-jsp in Tools->Options in studio menu):

1. Open any block you want to put your code in.
2. Click on the Edit button which will open an editor.
3. You may have to include classes as necessary in the beginning of the code block.
4. You can put in your code in processBegin(PageContext), processAnywhere(PageContext) or processEnd(PageContext).
(I would suggest you move these utility code snippets to a support file or similar so you can just call the function from anywhere in the Studio code and helps eliminate redundancy. You can even create your own library of such stuff and put them in your server's library.)

<%@ page language="java" import="java.util.Date"%>
<%@ page language="java" import="java.text.SimpleDateFormat"%>
<%!
          // localPageContext - Contains the reference to the Page Context.  
  //                    Can be used o Access the HTTP Objects

//Can be used for writing the custom code that needs to get
//executed before the vxml page starts
            public void processBegin(PageContext localPageContext){
               String DATE_FORMAT = "yyyy-MM-dd";
               java.text.SimpleDateFormat sdf =
                        new java.text.SimpleDateFormat(DATE_FORMAT);
              Calendar cal1 = Calendar.getInstance();
              Calendar cal2 = Calendar.getInstance();
              cal1.set(2008, 10 , 31);
              cal2.set(2001, 11 , 30);
   
              //System.out.print(sdf.format(cal1.getTime()));
   
              if (cal1.before(cal2)) {
                  System.out.print(" is before ");
              }
              if (cal1.after(cal2)) {
                  System.out.print(" is after ");     
              } 
              if (cal1.equals(cal2)) {
                  System.out.print(" same as ");     
              } 
            }
//Can be used for writing the custom code that needs to get
//executed before the vxml page ends
            public void processAnywhere(PageContext localPageContext){

            }
//Can be used for writing the custom code that needs to get
//executed after the vxml page ends.can be used for doing cleanup
            public void processEnd(PageContext localPageContext){

            }
PS: I used to work on a different platform before that provided all the APIs for these kind of stuff. But the cool thing here is you can build your own stuff which is very easy coz it Java, ASP etc(you can easily google and get examples on how-to's).
« Last Edit: February 23, 2009, 02:23:31 PM by Infinity »

Offline rlcrockett

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: GVP 7.6 How to code to compare variables
« Reply #2 on: February 23, 2009, 03:14:26 PM »
can you also show this to me with one variable being passed to the routine and tell me how test once outside of the code block (ports, etc.)

Offline Infinity

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: GVP 7.6 How to code to compare variables
« Reply #3 on: February 23, 2009, 04:12:17 PM »
I'm not sure what you mean by "outside of the code block". If you want to pass variables and have your studio app modularized then you have to go for sub-callflows(depending on how much functionality you want to add to it) it wouldn't help much to put in just a date validation in a sub-callflow in which case you can write the date comparison function in your include file (eg: pagesupport.inc) or you can create your own library(.jar) and add it to the WEB-INF/lib directory on the server.

One way you can test the functionality alone is by just running the jsp file from your browser. For example, if your block creates a jsp file called date_check.jsp and your application directory is "Test" on the web server, you can type in http://<serverip>:8080/Test/date_check.jsp and it should work. Also please remember to run all the jsp files(start block for example) that set your application properties etc before running the date_check. It would depend on how your application is coded too.

Here's an example to do it via pagesupport.inc (<tomcat_dir>/webapps/<app>/StudioIncludes/pagesupport.inc):

This function can be coded in pagesupport.inc as:

            void dateComp(Date d){
              String DATE_FORMAT = "yyyy-MM-dd";
              java.text.SimpleDateFormat sdf =
                        new java.text.SimpleDateFormat(DATE_FORMAT);
              Calendar cal1 = Calendar.getInstance();
              Calendar cal2 = Calendar.getInstance();
              cal1.setTime(d);
              cal2.set(2001, 11 , 30);
 
              //System.out.print(sdf.format(cal1.getTime()));
 
              if (cal1.before(cal2)) {
                  System.out.print(" is before ");
              }
              if (cal1.after(cal2)) {
                  System.out.print(" is after ");   
              }
              if (cal1.equals(cal2)) {
                  System.out.print(" same as ");   
              }
            }

Then you can call this function in your Studio code as:
            public void processBegin(PageContext localPageContext){
                  .........
                  .........
                  dateComp(date);
                  .......
                  .......
            }

The print output will be redirected to <tomcat_dir>/logs/stdout_<date>.log on the server.
I would think the best approach would be to create your own java library coz you may wish to add more date processing at some point. Adding more code to these include files makes it difficult to maintain and testing it stand-alone is a pain too. If you have a Java library you can test it on the fly(I mean only the utility functions without involving the IVR).

Hope this helps.

Offline rlcrockett

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: GVP 7.6 How to code to compare variables
« Reply #4 on: February 23, 2009, 11:25:59 PM »
Looks like your examples are JSP, but my system is set up to generate (Studio) ASP.  I know how to switch studio to generate JSP, but I don't know how to change GVP to use the new code.  So do you have a similar example, to the last one that you put in the pagesupport.inc file?

Offline postx

  • Newbie
  • *
  • Posts: 37
  • Karma: 0
Re: GVP 7.6 How to code to compare variables
« Reply #5 on: February 24, 2009, 12:42:57 PM »
[quote author=rlcrockett link=topic=3888.msg16925#msg16925 date=1235431559]
Looks like your examples are JSP, but my system is set up to generate (Studio) ASP.  I know how to switch studio to generate JSP, but I don't know how to change GVP to use the new code.  So do you have a similar example, to the last one that you put in the pagesupport.inc file?
[/quote]

You have to chnage the URL in your provisioning

http://server:PORT/app-dir/app.asp => http://server:PORT/app-dir/app.jsp that it.

Offline Infinity

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: GVP 7.6 How to code to compare variables
« Reply #6 on: February 24, 2009, 01:32:06 PM »
I'm sorry I can't be of much help with ASP stuff. I've never tried it.
You could try generating a test application in JSP but if you are trying to add this date functionality to an existing application set up to run via ASP, then it's a completely different thing. I guess you might be running your ASP applications on IIS. To serve JSP pages you  need to have Tomcat(generally used) or similar.

Offline rlcrockett

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: GVP 7.6 How to code to compare variables
« Reply #7 on: February 24, 2009, 05:18:34 PM »
I tried changing the URL in provisioning to point to the JSP start file, but that didn't work.  Tomcat has always been running.

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7641
  • Karma: 56330
Re: GVP 7.6 How to code to compare variables
« Reply #8 on: February 24, 2009, 05:39:37 PM »
Did you deployed the WAR file? If you open a browser with that URL does it work?

Offline Infinity

  • Newbie
  • *
  • Posts: 18
  • Karma: 0
Re: GVP 7.6 How to code to compare variables
« Reply #9 on: February 25, 2009, 03:21:23 PM »
Have you had any luck getting this to work?