Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements

Welcome to Cisco Support Community. We would love to have your feedback.

For an introduction to the new site, click here. If you'd prefer to explore, try our test area to get started. And see here for current known issues.

New Member

How can I use CRS script variables in a java block?

Hi,

I have a CRS script that reads an XML file and checks holiday dates. I need to check dates offset from the current date, so I’m using the java Calendar object (java.util.Calendar). For example, let’s say I want the date 4 days back from today. Using a “Set” step, I code;

{java.util.Calendar cal = java.util.Calendar.getInstance();

cal.add(cal.DATE, -4 );

return cal.getTime();}

Here’s my problem, I need the offset to be a variable from the script. In my script I have defined “nDateOffset” as an int and set to the value -4. But when coded like this;

{java.util.Calendar cal = java.util.Calendar.getInstance();

cal.add(cal.DATE, nDateOffset);

return cal.getTime();}

The script fails with NullPointerException. Does anyone have a suggestion or solution?

Thanks

2 REPLIES

Re: How can I use CRS script variables in a java block?

Did you debug and see which line it is failing at? The cal.add line or cal.getTime() line?

I don't know if you can get the currentTime for 4 days back. The getTime is the current time. So, it might be failing at the getTime line.

Debug and let me know.

New Member

Re: How can I use CRS script variables in a java block?

The java code executes as expected and returns the date 4 days back. It only fails when "-4" is changed to the script variable "nDateOffset". On a side note, if I mark nDateOffset as Final, the code will work, but this defeats the purpose of the variable.

122
Views
0
Helpful
2
Replies