cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
387
Views
0
Helpful
2
Replies

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

fpizzuta
Level 1
Level 1

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 2

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.

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.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: