1 2 Previous Next 25 Replies Latest reply on Sep 11, 2014 6:38 AM by paul.hyman

    Window calculation help!!!

    Apprentice

      Morning All


      I'm having some serious issues with my calculation, I  have read through the Dynamic windows document and appreciate that it is an overview of "Boo" within Service Desk however I could do with some pointers or advice. I have the following window design within my survey. What I want to happen is the feedback field at the bottom to be hidden unless any of the answers to the questions above are set to 1,2 or 10. Then if they are the feedback option is to be visible and set to mandatory.

       

      None of the options are mandatory/hidden at the moment.

       

      Below my window you can see my calculation and the error I get and I have no idea how to move forward. As you can see I have 4 questions set at the moment I am testing it against 1 question until I get it right. Thanks in advance.

       

       

      import System

      static def GetAttributeValue(_IncidentSurveyv2):

        _IncidentSurveyv2._Feedback = true

        _IncidentSurveyv2._Feedback = false

        if _IncidentSurveyv2._Question1  <'3' or '>9'

        return String.Format(":SetHidden(_Feedback, {0});:SetMandatory(_Feedback,{1});",_IncidentSurveyv2._Feedback,_IncidentSurveyv2._Feedback)

      Boo Error calc.PNG

       

      Boo error wind.PNG

      StuMcneill any advice on this?

       

      Nay

        • 1. Re: Window calculation help!!!
          Expert

            if _IncidentSurveyv2._Question1  <'3' or '>9'

           

          1. Need a colon at the end.

          2. Can't do math with strings.  '2' is not less than '3', 2 is less than 3.  You will need to check for each value.

          • 2. Re: Window calculation help!!!
            Apprentice

            I tried those and it still fails no matter what I try I get an error, damn Boo!

            So I copied the following to see if it's me and replaced the fields with mine and I still get errors.


            import System

            static def GetAttributeValue(Process_Object):

                       Variable1 = true

                       Variable2 = false

                      if Process_Object.Related_Object != null and Process_Object.Related_Object.Attribute == 'value':

                                 Variable1 = false

                                 Variable2 = true

                      return String.Format(":SetHidden(TargetAttribute, {0});:SetMandatory(TargetAttribute, {1});",Variable1, Variable2)



            import System

            static def GetAttributeValue(_IncidentSurveyv2):

                       _IncidentSurveyv2._Feedback = true

                      if _IncidentSurveyv2._Question1 != 1 and _IncidentSurveyv2._Question2 == '2':

                                 _IncidentSurveyv2._Feedback = false

                      return String.Format(":SetHidden(_Feedback, {0});:SetMandatory(_Feedback, {1});", _IncidentSurveyv2._Question1, _IncidentSurveyv2._Question2)

             

            The error I get now is repeated on line 4 twice, 5 and 6 twice

             

            BCE0005: Unknown Identifier: '_IncidentSurveyV2'.


            Now I used the place holders from the attributes selection I didn't type these myself so why is this now showing I'm doing something wrong?

            • 3. Re: Window calculation help!!!
              masterpetz ITSMMVPGroup

              Hi,

               

              When I look at you calc and compare it to the error message, I get confused about the capital "V" in the error message but I didn't see this in your calc. You should check your calc again.

               

              Kind regards

              Christian

              • 4. Re: Window calculation help!!!
                Apprentice

                Hey MasterPetz

                 

                Thanks for the response, that error capital "V" is my typo as it is a small v in the error.

                 

                Thanks


                Nay

                • 5. Re: Window calculation help!!!
                  aparker Employee

                  Hi Nay,

                   

                  Here is an example of a calculation that I use in a Change window. It is a little more complex, but I think it will highlight what you may have been getting an error with...

                   

                  import System

                  static def GetAttributeValue(Change):

                   

                    DescriptionMandatory = false

                    ReasonHidden = true

                    ReasonMandatory = false

                    BenefitHidden = true

                   

                    if Change._ChangeType1 != null and Change._ChangeType1._ChangeType == "Major":

                        DescriptionMandatory = true

                        ReasonHidden = false

                        ReasonMandatory = true

                        BenefitHidden = false

                    elif Change._ChangeType1 != null and Change._ChangeType1._ChangeType == "Emergency":

                        DescriptionMandatory = true

                        ReasonHidden = false

                        ReasonMandatory = true

                        BenefitHidden = true

                    elif Change._ChangeType1 != null and Change._ChangeType1._ChangeType == "Standard":

                        DescriptionMandatory = false

                        ReasonHidden = true

                        ReasonMandatory = false

                        BenefitHidden = true

                   

                    return String.Format(":SetMandatory(Description,{0});:SetHidden(_Reason,{1});:SetMandatory(_Reason,{2});:SetHidden(_Benefit,{3});",DescriptionMandatory,ReasonHidden,ReasonMandatory,BenefitHidden)


                  You need to define some local variables within the calculation to manage the control of the behaviour you want applied to each attribute on the window. I think what you are doing is using the actual attribute. I always create a series of variable that link the attribute name and the behavior together.  Try and replace the _IncidentSurveyv2._Feedback = true with something like FeedbackMandatory = true.


                  Andy

                  1 of 1 people found this helpful
                  • 6. Re: Window calculation help!!!
                    Apprentice

                    Hi Andy

                     

                    I really appreciate you taking the time to provide an example, I think I understand now and will give this a try based on your example and see what happens. Will get back to you shortly.

                     

                    Thanks

                     

                    Nay

                    • 7. Re: Window calculation help!!!
                      Apprentice

                      Hey Andy

                       

                      Think I'm getting there, so thanks.

                       

                      Ok so now on reworking the calculation.

                       

                      I've got the following in the editor window.

                       

                      import System
                      static def GetAttributeValue(_IncidentSurveyv2):
                      FeedbackMandatory = false
                      FeedbackHidden = true
                      if _IncidentSurveyv2._Question1 != "1":
                        FeedbackMandatory = true
                        FeedbackHidden = false
                      elif _IncidentSurveyv2._Question1 != "2":
                        FeedbackMandatory = true
                        FeedbackHidden = false
                      elif _IncidentSurveyv2._Question1 != "10":
                        FeedbackMandatory = true
                        FeedbackHidden = false
                      return String.Format(":SetHidden(_Feedback, {0});:SetMandatory(_Feedback, {1});",FeedbackMandatory, FeedbackHidden)

                       

                      Syntax is valid but when I test the calculation I get the following error.

                       

                      Test Calculation

                      No default query has been set for this business object. please contact your administrator

                       

                      Not sure if I'm supposed to get this??

                      • 8. Re: Window calculation help!!!
                        aparker Employee

                        So all this is saying is that because the object that you are running the calculation on is a collection, the system doesn't know which instance it should be looking at when the calculation is triggered. Save the calculation and then create a query on the object which just sorts is in date order. There doesn't have to be any specific attributes, so just pick one. Once you have created the query go to the object in Object Designer and in the Properties set the Default Query to the one you have just created. If you're as bad as I am when it comes to naming conventions, I always name my queries DQ-ObjectName.

                         

                        Andy

                        • 9. Re: Window calculation help!!!
                          aparker Employee

                          I should have also said that it is good practice to add the Null test into each condition on the calculation. This just make sure that there are no annoying errors.

                           

                          A

                          • 10. Re: Window calculation help!!!
                            Apprentice

                            Awesome,

                             

                            So I am just added a new option to the calculation that states

                            if _IncidentSurveyv2._Question1 != "null":

                              FeedbackMandatory = false

                              FeedbackHidden = true

                             

                            and do this for every question so that until an option is chosen it sets condition?

                             

                            Thanks

                             

                            Nay

                            • 11. Re: Window calculation help!!!
                              aparker Employee

                              If you look at what I did, you can see I have the test as part of each if statement...

                               

                              if Change._ChangeType1 != null and Change._ChangeType1._ChangeType == "Major":

                              • 12. Re: Window calculation help!!!
                                Apprentice

                                Hey Andy

                                 

                                Last question before I mark your answer above as correct. cheeky I know.

                                 

                                Ok so the calculation is working on the window as it's making the field I want hidden however when I select the options I have stated in my if statements it's not showing.

                                 

                                I have the "calculate on change" option set in the window

                                The calculation as you can see below is on the window so I can see if it's working or not. the dependencies are set as below also so where am I going wrong with this?

                                calcuation window.PNGwebdesk view calc.PNG

                                 

                                Thanks again

                                 

                                Nay

                                • 13. Re: Window calculation help!!!
                                  Expert

                                  I do an IISRESET after making changes to calculations. Your error "BCE0005: Unknown Identifier: '_IncidentSurveyV2'." I believe is a result of still looking at the old calculation.  IISRESET forces the clearing of memory cache.  Currently there is no way to test for the initial null possibilities from the editor.  The test only checks against existing incidents (in this case).  You can't simulate a new incident for testing, although there is a ER to do that (see below).  Anyone that uses calculation will want this ER.  The ability to test a calculation in the editor is a huge time saver.  Please vote, this would really be handy.

                                   

                                  Calculation Test: New Incident

                                  • 14. Re: Window calculation help!!!
                                    Apprentice

                                    I have not done/had to do an IIS reset all day today with the calculation changes Andy has helped me with. I now have the calculation 50% there just having issues as above with it doing as expected,

                                     

                                    I have voted for your ER as it would be beneficially indeed.

                                     

                                     

                                    Nay

                                    1 2 Previous Next