Facility Control

 View Only
  • 1.  Logical operation in IF / Else statements

    Posted 03-16-2021 03:44

    I have a very nice (but not to optimized - yet) little panel going. I was wondering if it is possible to have logical operations going in an If/Else statement. Something like this:

    IF
    variable1 == "Y"  and variable2 == "N"
    THEN
    variable3 = abc
    or
    variable1 == "N" and variable2 == "N"
    THEN
    varible3 = def

    ELSE
    variable3 = ghi

    Is something like this available in DashBoard

    Thanks,
    Jerry



  • 2.  RE: Logical operation in IF / Else statements

    Posted 03-16-2021 15:22

    ogScript is based on javascript.   

    So if you don't know how to do something, you can always google "javascript if statement", and get some information that way.   It does not cover all ogscript stuff, but for basics like conditionals and loops, it works. 

    So for ifs, you can look here: https://www.w3schools.com/js/js_if_else.asp

    For logical statements (ands and ors) you can look here: https://www.w3schools.com/js/js_comparisons.asp

    Your if statement should look something like this:

    var v1 = "yes"

    var v2 = "yes"

    if (v1 == "yes" && v2 == "yes") {
      v3 = "abc"
    else if (v1 == "no" && v2 == "no") {
      v3 = "def"
    else {
      v3 = "ghi"
    }


    #DashBoard


  • 3.  RE: Logical operation in IF / Else statements

    Posted 03-17-2021 02:35

    Thanks for the pointer - was wondering about the && and || 
    Onward into a logical nightmare!!

    -Jerry


    #DashBoard


  • 4.  RE: Logical operation in IF / Else statements

    Posted 03-17-2021 18:46

    Ben - while the && for the 'and' operation seem to be right for javascript and some dashboard things - I'm getting this error. Any idea what this means?

     


    #DashBoard


  • 5.  RE: Logical operation in IF / Else statements

    Posted 03-17-2021 18:52

    You are getting this because "&" is a special character in XML and the grid files are stored as xml.

    If you use the built-in editors for tasks, it converts the & into the "&" string that XML needs.   But if you type the "&" directly in the source, then it does not get replaced, and DashBoard will throw that error.

    So you can do one of two things:

    1. Use the built-in dashboard editor to edit your tasks.

    2. Use "&amp;" instead of "&" in your tasks.    Also, if you use "<" or ">" anywhere in your scripts, you would need to use "&lt;" and "&gt" instead (which stands for lesser than, and greater than).


    #DashBoard


  • 6.  RE: Logical operation in IF / Else statements

    Posted 03-17-2021 19:37

    thank you so much -- the &amp; solved it !!

    -Jerry


    #DashBoard