Skip navigation
1 2 Previous Next 638 Views 18 Replies Latest reply: Apr 18, 2012 6:25 AM by KarenPeacock RSS
hhmis Apprentice 44 posts since
Jan 3, 2010

Has received 1 of 9 achievements.
Currently Being Moderated

Apr 13, 2012 9:02 AM

Return text value if Boolean is true or false

Greetings,

 

I'm trying to come up with a calculation for a stirng attribute that will detect if a boolean is true or false, then depending on which, it will return a text value of "yes" or "no". I think I'm close, but seem to be struggling getting it right. I'm fairly new to calculations, so don't laugh to hard at my attempt :

 

import System

static def GetAttributeValue(Request):

if Request._SystemAccessECW == 'True'
Value= "Yes"
return Value
if Request._SystemAccessECW == 'False'
Value= "No"

 

 

Thanks in adavance

  • elizabethcombrink Employee 473 posts since
    Dec 19, 2008

    Has received 6 of 9 achievements.
    Currently Being Moderated
    1. Apr 13, 2012 9:46 AM (in response to hhmis)
    Re: Return text value if Boolean is true or false

    Try this - make sure you keep the spaces as I've got them

     

    import System
    static def GetAttributeValue(Request):
    Value = "Yes"
    if Request._SystemAccessECW == 'True':
      Value= "Yes"
    else:
      Value = "No"
    return Value

     

     

    In Stu's guide to calculations, he mentions the Boo Primer which helps loads to get the syntax right!

  • elizabethcombrink Employee 473 posts since
    Dec 19, 2008

    Has received 6 of 9 achievements.
    Currently Being Moderated
    3. Apr 13, 2012 10:03 AM (in response to hhmis)
    Re: Return text value if Boolean is true or false

    1 space needed in lines 3, 4 and 6, and 2 spaces for line 5 and 7.

     

    Home time for me.

  • paul.enkelaar Expert 209 posts since
    Sep 5, 2010

    Has received 6 of 9 achievements.
    Currently Being Moderated
    5. Apr 15, 2012 4:53 PM (in response to hhmis)
    Re: Return text value if Boolean is true or false

    Hi

     

    It could just be how I am looking at it, but it looks like the last line is indented the same as the line above it.  Won't this mean that the only time that the "return" statement runs is when the "else" section is fired.  I think you may need to remove a space from the last line.

     

    Cheers


    Paul

  • Expert 233 posts since
    Jan 27, 2009

    Has received 7 of 9 achievements.
    Currently Being Moderated
    6. Apr 16, 2012 12:48 AM (in response to hhmis)
    Re: Return text value if Boolean is true or false

    To test for a boolean value, don't quote the True or False in your check, see below-

     


    import System

    static def GetAttributeValue(Request):

    if Request._SystemAccessECW == true

    Value= "Yes"

    else:

    Value= "No"

    return Value

     

    Cheers,

    Hadyn

  • Expert 233 posts since
    Jan 27, 2009

    Has received 7 of 9 achievements.
    Currently Being Moderated
    8. Apr 16, 2012 5:56 AM (in response to hhmis)
    Re: Return text value if Boolean is true or false

    Did you use a capital T in True? I think this is a case sensitive item, it either needs to be capitalised or not, can't remember sorry, so if it is capitalised then try without a capital T.

     

    Cheers,

    Hadyn

     

    P.S. that calculation does contain an if-then-else statement already.

  • csimpson@kumc.edu Expert 614 posts since
    Jan 6, 2010

    Has received 4 of 9 achievements.
    Currently Being Moderated
    9. Apr 16, 2012 7:11 AM (in response to Hadyn Dawson)
    Re: Return text value if Boolean is true or false

    Somewhere I saw it done this way and it works for me ...

     

    if Request._SystemAccessECW.ToString() == 'True'

     

    I usually see everything after the Static line is indented 1 space.  Anything to be completed within an IF statement gets another indent.  Your example would end up with:

    import line, no spaces

    static line, no spaces

    if line, 1 space

    value line, 2 spaces

    else line, 1 space

    value line, 2 spaces

    return line, 1 space

     

    If you have 2 spaces before the return value, then it will only return a value in the else situation and the true situation will never return a value.

     

    Of course nested if statements could require additional spaces and it strts getting messy. 

     

    I have an enhancement request for a BOO debug tool so we can step line by line through a calculation and see the values.  Visual Studio does an excellent job of tracing and would be a good example of how I would like to see it work.

  • csimpson@kumc.edu Expert 614 posts since
    Jan 6, 2010

    Has received 4 of 9 achievements.
    Currently Being Moderated
    11. Apr 16, 2012 12:36 PM (in response to hhmis)
    Re: Return text value if Boolean is true or false

    From the looks of it (hard to tell) it appears that everything below the Static line is not indented, all of my calculations are indented 1 space.  At the end of the line is a ":" which means the next section should be indented.  Notice that after the IF statement, the value is indented 2 spaces.  The ELSE is not needed because the 'No' is assumed.

     

    The other thing we don't know is if there is a default value.  If there is no default value then a third option exists (no choice has been made).  I recommend making True or False a default value.  I also recommend making it a mandatory value so it shows up on WebAccess windows as a check box and not a drop down value.  Might as well do both.

     

    I also don't see that Value has been initialized to a string so it might be expecting an integer.  This is how I would do it:

     

    import System
    static def GetAttributeValue(Request):
     Value = 'No'
     if Request._SystemAccessECW.ToString() == 'True':
      Value= 'Yes'
     return Value
    

     

    The courier font helps show the spacing a little bit better.

     

    The ToString returns a string and not a boolean value so you need to check it against a string.

  • csimpson@kumc.edu Expert 614 posts since
    Jan 6, 2010

    Has received 4 of 9 achievements.
    Currently Being Moderated
    13. Apr 16, 2012 1:22 PM (in response to hhmis)
    Re: Return text value if Boolean is true or false

    Agreed, a manual with LOTS of examples would really be nice.  Part of the problem is they don't support BOO.  It's in the product, as you can see here many people use it, but support doesn't officially support it.  These forums are the basic support mechanism for BOO and we keep passing around examples.  I am half tempted to start my own manual but there is still so much I don't know.

     

    On the positive side it does some amazing stuff and really makes Service Desk a much more powerful package.

  • Expert 233 posts since
    Jan 27, 2009

    Has received 7 of 9 achievements.

    Carl,

         Can you post up the link for the enhancement request, I would vote for a debug tool definitely. Also, I believe LANDesk does support the calculation feature, and any OOTB calculations but what they don't support is custom calculations.

     

    As it stands, you can do some debugging using tracing in the TPS.config, however this isn't always helpful. Also, for examples/info on writing BOO code I've found 3 things have really helped when developing calculations-

     

    • The BOO Primer and wider tutorial information found at http://www.boo.codehaus.org
    • Googling .NET functions and methods, as BOO can use a large portion of these functions, things like ToString() or Substring, plus various date time operators.
    • Googling Python syntax - while not explicitly a Python interpreter the BOO engine seems to use a near identical syntax and structure as Python code so I've found that where syntax and structure issues are letting me down I can usually google for some Python based examples to find the solution, as there is way more info on Python online than BOO.

     

    Cheers,

    Hadyn

1 2 Previous Next

More Like This

  • Retrieving data ...

Bookmarked By (1)

Legend

  • Correct Answers - 20 points
  • Helpful Answers - 10 points
LANDESK Community powered by Jive SBS® 4.5.7.1  |  Legal Notices  |  Privacy Policy  |  Icon 

TweeterOn Twitter  |  Icon FacebookOn Facebook © 2007 LANDESK Software