-4

I'm getting an error with my javascript: "missing ; before statement".

I'm trying to read in a date, add 6 months onto the date if it meets a certain criteria ( joiner type in this case) and if not just return that date.

I can't see whats wrong here, it must be something small, any ideas??

Thanks!

function checkenddate(Par) {
   var array = Par.split("!!");

   var usermskey = array[0];
   var date = array[1];
   var joinertype = array[2];

   saprep = UserFunc.uGetConstant("glb.REPOSITORY_ECC");
   attr1 = "Z_VALIDTO" + saprep;

   uWarning("Attribute: " + attr1);

   if (date == null && joinertype.equals("Contractor"))
   {
       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
       Calender c = Calender.getInstance();
       c.setTime(sdf.parse(date));
       c.add(Calender.MONTH, 6);
       enddate = sdf.format(c.getTime());

       uWarning("End Date:" + enddate);

       OutString = uIS_SetValue(usermskey, 0, attr1, enddate);

       return enddate;
   } else {
       OutString = uIS_SetValue(usermskey, 0, attr1, date);
       return date;
   }
 }
famousgarkin
  • 13,687
  • 5
  • 58
  • 74
sean_2013
  • 3
  • 4
  • 3
    **Which line** throws that error? – JJJ Apr 20 '15 at 11:05
  • 3
    It appears you're confusing Java and JavaScript -- see [What's the difference between JavaScript and Java?](http://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java) – Qantas 94 Heavy Apr 20 '15 at 11:06
  • See also `Calender c = Calender.getInstance();` as well as the answers below. – Andy Apr 20 '15 at 11:09
  • I dont get a line that throws an error, just the error: missing ; before statement............. Andy is there something wrong with the way im declaring a Calender?? Thanks – sean_2013 Apr 20 '15 at 11:37

2 Answers2

2

Thats not valid javascript. You can't have typed variables such as SimpleDateFormat sdf = new blah(). Change your types to var and it will work as expected.

var sdf = new SimpleDateFormat("yyyy-MM-dd");
var c = Calender.getInstance();
Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68
  • 1
    There are more variables in need of that correction: saprep, attr1, and enddate, unless they're defined out of the function – Morb Apr 20 '15 at 11:11
  • 1
    I tried declaring the variables in this function, changing the simpledateformat type to "var" but no luck... Failed running function in string "$FUNCTION.checkenddate(285342!!2015-04-29!!Contractor)$$". Marking entry as failed. Exception was: org.mozilla.javascript.NotAFunctionException: glanbia_checkenddate(285342!!2015-04-29!!Contractor) – sean_2013 Apr 20 '15 at 11:33
  • also changed the calender type but getting a new error...............Executing checkenddate(285343!!2015-04-28!!Contractor) got RuntimeException - undefined: "SimpleDateFormat" is not defined. HINT: Check line 18 in the script glanbia_checkenddate looks like i need to change the delcaring of the SimpleDateFormat?? – sean_2013 Apr 20 '15 at 11:40
  • Looks like i just needed to import the java classes...works like a charm! thanks guys – sean_2013 Apr 20 '15 at 11:56
1

This is not how you declare a JS variable:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

You need this instead:

var sdf = new SimpleDateFormat("yyyy-MM-dd");

I would recommend using one of the linting tools online (e.g. JSHint or JSLint) to help track down these issues - very handy.

Paddy
  • 33,309
  • 15
  • 79
  • 114