0

I have the following code that I am writing inside BRIO (Hyperion Interactive Reporting Studio). The code is either in JavaScript or JScript, though I am not sure which as I am just learning the syntax and am not sure how they differ.

Anyway, I am getting syntax Script(line number) missing; before statement error on the following lines:

if (xYear == 2012 && yMonth == 10) {stopIt = "Yes"} else (yMonth == 12) {stopIt = "Yes"}

and

var myDate = New Date(xYear, yMonth, 1)

in the code below.

var xYear
var yMonth

for (j = 2009; j =  2012; j++)

{ 

    xYear = j

    if (xYear == 2009) {yMonth = 7} else {yMonth = 1}

    var StopIt = "No"

    Do 

    {
    var myDate = New Date(xYear, yMonth, 1)
    Alert (myDate)

    //var myQuery = ActiveDocument.Sections["qry_billing"]

    //myQuery.Limits["Accounting Year Month"].CustomValues.RemoveAll()
    //myQuery.Limits["Accounting Year Month"].CustomValues.Add(myDate)
    //myQuery.Limits["Accounting Year Month"].SelectedValues.Add(myDate)

    //myQuery.Process()

    //var Path = "W:\\Major Accounts\\Alliance Process\\AAA\\reference_files\\Results"
    //var File = "Results" + "_" + xYear + "_" +  yMonth+ " .txt"

    //ActiveDocument.Sections["Results"].Export(Path + "\\" + File,bqExportFormatText,true)

    yMonth = yMonth + 1

    if (xYear == 2012 && yMonth == 10) {stopIt = "Yes"} else if (yMonth == 12) {stopIt = "Yes"}
    }

    While (stopIt != "Yes")

}

Can someone please help me fix this issue, as I don't understand why it's asking me for the ;, as I thought it wasn't even needed in BRIO document scripts.

Scott Holtzman
  • 27,099
  • 5
  • 37
  • 72

2 Answers2

7
else (yMonth == 12)

Should be:

else if (yMonth == 12)

And when you indent the code properly, it's easy to notice this error:

if (xYear == 2012 && yMonth == 10) {
    stopIt = "Yes"
} 
else (yMonth == 12) { // shoule be: else if (yMonth == 12) {
    stopIt = "Yes"
}

Notes: javascript is case sensitive which means

  • Do isn't do
  • so as for alert instead of Alert
  • new instead of New

But semicolons are not mandatory, you can use them or use not, as you wish.

Update:

From looking at the full code you posted, man, it has lots of weird things.

for (j = 2009; j =  2012; j++)

Should be something like:

for (var j = 2009; j <= 2012; j++)
...

You define a variable:

var StopIt = "No"

But use stopIt instead:

stopIt = "Yes"

You should take a javascript course\tutorial, it's not that difficult to learn, but your code in it's current state is totally broken!

gdoron
  • 147,333
  • 58
  • 291
  • 367
  • thanks for this catch, however, it doesn't solve my posted problem. – Scott Holtzman Nov 05 '12 at 16:42
  • 1
    @ScottHoltzman. Then you have other errors in your code. What is the new error you're getting? – gdoron Nov 05 '12 at 16:43
  • semicolon after stopIt = "Yes" – Sajjan Sarkar Nov 05 '12 at 16:43
  • That fixed the `If Then Else If` statement! Thanks. @Teemu's comment fixed the other line. It was a case sensitivity thing. – Scott Holtzman Nov 05 '12 at 16:53
  • @ScottHoltzman, Tips from me: 1) Use `JSlint`. 2) write small amount of code and check if it works, then continue to the next small amount test it again... until you finish. – gdoron Nov 05 '12 at 16:54
  • Thanks for the edits / updates and tips gdoron. Very appreciative. I am trying something on the fly at the moment, these lessons are appreciated for my future learning. – Scott Holtzman Nov 05 '12 at 17:00
  • @SajjanSarkar, You should know that semicolons are not mandatory in javascript. some loves it some hates it, some, like me, don't give a damn. :) – gdoron Nov 05 '12 at 17:03
  • @gdoron the OP is using Brio / Hyperion BI / Oracle EPM, which uses its own proprietary version of JavaScript. A lot of what you're saying is wrong because of that. For instance, the `alert()` function allows Hyperion to use the JavaScript version, but `Alert()` calls the Hyperion-specific version which takes different parameters. Another example (which he probably isn't using correctly anyway) is that if a variable is not declared with `var` is a way to create a global variable for the application (though it's proper form to declare those in the onStartup() Document script). – undrline - Reinstate Monica Jul 27 '18 at 17:11
0

For clarity sake, the answer to my question was two-fold, based on gdoron's very helpful and informative answer and Teemu's comment under my original post. To sum up the answer I've answered my own question below:

The error in this statement

if (xYear == 2012 && yMonth == 10) {stopIt = "Yes"} else (yMonth == 12) {stopIt = "Yes"}

is that is was missing if after the else

So it should look like this:

if (xYear == 2012 && yMonth == 10) {
    stopIt = "Yes"
}
else if (yMonth == 12) {
    stopIt = "Yes"
}

The error in this statement

var myDate = New Date(xYear, yMonth, 1)

was that New should not have been capitailized. So it should be written as:

var myDate = new Date(xYear, yMonth, 1)
Scott Holtzman
  • 27,099
  • 5
  • 37
  • 72