13 Replies Latest reply on Feb 1, 2012 3:36 PM by hadyn.dawson

    Process Design - Calculation on Status

    Rookie

      I'm having some problems creating a calculation to do the following:

       

      If the Problem attached to the Incident is at either  "'Investigating Root Cause Workaround Identified' or 'Root Cause Identified Workaround Identified' then give value as "true" otherwise "false".

       

      This is so that i can include this in a decision in the Incident Process.

       

      I've tried to write the below calculation to do the above but it doesn't seem to work? Im a newbie with calculations if im honest.

       

      import System
      static def GetAttributeValue(Incident):
      Value = 'False'
      if Incident.IncidentProblem.Problem.Status.Title!='Investigating Root Cause Workaround Identified':
        Value='True'
      if Incident.IncidentProblem.Problem.Status.Title!='Root Cause Identified Workaround Identified':
         Value='True'
      return Value


      Appologies if its simple school boy error, but im sure the error will jump out at some Landesk Servicedesk  Calculation Guru!

      Thanks

      Adam

        • 1. Re: Process Design - Calculation on Status
          Expert

          We don't use Problems but I noticed that you only opened Incident.  I have not worked with 2 different objects (incident and Problem) in the same calculation so this will be a good example when you get a solution.  I suspect this is where your problem is.

          • 2. Re: Process Design - Calculation on Status
            Expert

            Hi Adam,

             

            As you can have multiple problems associated with an Incident you will likely need to tell it which one you want. In most cases the latest one should prove sufficient, so something like this may work better-

             

            import System
            static def GetAttributeValue(Incident):
            Value = 'False'

            Prob = Incident.IncidentProblem.Problem.Latest()
            if Prob.Status.Title!='Investigating Root Cause Workaround Identified':
              Value='True'
            if Prob.Status.Title!='Root Cause Identified Workaround Identified':
               Value='True'
            return Value

             

            Hope this helps.

             

            Cheers,

            Hadyn

            • 3. Re: Process Design - Calculation on Status
              Rookie

              Hi Hadyn,

               

              I've tried the below formula but this is still not showing a value of true/false depending on the status of the latest attached problem.

               

              Before creating the calculation as a condition, i have been creating it as an extra attribute on the Incident Object so that i can then display the field on the incident window to check the formula, and ensure i get the correct results. Otherwise i was having to amend the process, remove the calculation and amend then re-add it to the process, which takes time.


              I've set this calcualation type as "After Read" and displayed this attribute on the Incident window, so i can check what value is being set.

               

              Is it possible to link between 2 objects on a calculation?


              Has anyone else been able to set a calculation based on a different object's status?

               

              Many thanks


              Adam

              • 4. Re: Process Design - Calculation on Status
                Expert

                I have never seen an example of that.

                 

                I suppose you could have another line to open Problem (static def GetAttributeValue(Problem).  I just don't know how to link them.  Technically your could search for each record and then do your calculation but that would be a lot of work/stress on the database.

                • 5. Re: Process Design - Calculation on Status
                  ProServices

                  If you're writing a condition where you need to compare against a collection, I'd use something along the following lines.

                   

                  Import System

                  status def GetAttributeValue(Incident):

                  Value = 'False'

                  for CurrentProblem in Incident.Problems:

                    if ((CurrentProblem.Status.Title = 'Investigating Root Cause Workaround Identified') or (CurrentProblem.Status.Title = 'SomeOtherProblemStatusTitle')) == 'True':

                     Value = 'True'

                  return Value

                   

                  This should search through all the problems associated to your incident and compare the title of the problem against whatever two values and if they equal EITHER of them, return true.

                   

                  This is for a condition on a process.

                  • 6. Re: Process Design - Calculation on Status
                    Rookie

                    Hi SBW,

                     

                    I've just tried the above calculation but im still getting errors (BCE0043: Unexpected token), I have checked the indenting several times over aswell.

                     

                    Whilst checking all references to calculations i found this on the calculation troubleshooting article:


                    "A particular scenario to take care with is when using the Parents/Children collections or Incident Problems, Incident Change, etc. many-to-many links between different modules.  The first level of the  relationship is a collection, followed by a one-to-one relationship to  the record on the other end therefore you cannot use Change.Children.Child.Title as the Children part of this path is the collection.  Using the Latest() function against these collections is not feasible as the links are not kept in any order.  You can however use the Count function and navigate through the records using For loops as follows:

                    Value = 'No children'
                    for item in Change.Children:
                    if Value == 'No children': Value = 'Children ID(s): ' + item.Child.Id
                    else: Value += ', ' + item.Child.Id
                    (This  example will return a list of Change Children IDs in the format  'Children ID(s): 123, 456, 789' or the text 'No children' if there are  none)
                    Notice that the loop is based on the Change.Children collection but within the loop you must also include the Child relationship before the attributes themselves."

                     

                    I've tried to workout what it means but im lost if im honest??

                     

                    Cheers

                    Adam

                    • 7. Re: Process Design - Calculation on Status
                      Expert

                      I have found BOO to be very picky.  I see your line ....

                       

                      if Value == 'No children': Value = 'Children ID(s): ' + item.Child.Id

                       

                      item.Child.id is a number.  My guess is that you have to transform it to text and/or you might have to use "&" in place of a "+".  You might have to use Concatenate to put them together.  One of these should lead you to success.  I have done mostly numbers and real simple if/then text stuff.

                      • 8. Re: Process Design - Calculation on Status
                        Expert

                        Hi Adam,

                             There was a mistake in my calculation I posted. Try this one-

                         

                        import System
                        static def GetAttributeValue(Incident):
                        Value = 'False'

                        Prob = Incident.IncidentProblem.Latest()
                        if Prob.Problem.Status.Title!='Investigating Root Cause Workaround Identified':
                          Value='True'
                        if Prob.Problem.Status.Title!='Root Cause Identified Workaround Identified':
                           Value='True'
                        return Value

                         

                        Cheers,

                        Hadyn

                        • 9. Re: Process Design - Calculation on Status
                          Stu McNeill Employee

                          Hi Adam,

                           

                          There are a few different ideas flying around but for clarify could you post your current calculation that is failing and what errors you're seeing?  Hadyn's suggestion will almost work but you need to replace using the .Latest() function with a loop to get your attached problem - as described in the section you pasted from the document you found.

                           

                          Carl - Boo uses "duck typing" (it will figure out you're adding it to a String so handle the data accordingly) so you don't need to worry about converting the Id from a number.

                           

                          Thanks

                          • 10. Re: Process Design - Calculation on Status
                            Stu McNeill Employee

                            Oh and when copying in calculation formula be careful the indents are being copied too and display OK once your reply has been posted.  The best way I find is to use the Syntax Highlighting feature.  Click the >> icon in the toolbar (next to the icon) then under Syntax Highlighting select Plain.  This gives you a text box to type into with much better formatting:

                             

                            Like this.
                            
                            • 11. Re: Process Design - Calculation on Status
                              Rookie

                              Hi Stu,

                               

                              Ok so the Calculation that i have got to at the moment is the following:

                               

                              import System
                              static def GetAttributeValue(Incident):
                               Value = 'False'
                               Prob = Incident.IncidentProblem.Latest() 
                               if Prob.Problem.Status.Title!='Investigating Root Cause Workaround Identified':
                                Value='True'
                                if Prob.Problem.Status.Title!='Root Cause Identified Workaround Identified':
                                 Value='True'
                               return Value
                              

                               

                              I've basically created a test attribute on the Incident Object and set the calculation to "After Read", this is so that i can show this on the Incident Window and preview what the calculation value would be at any point during a process. At the moment this field is just showing blank with no value.

                               

                              I couldnt make sense of the Looping, but to be fair im pretty new to calculations and only have a dabble every now and then..

                               

                              I am going to actually amend the process so a manual action is avaliable that pushes the Incident through 2 decisions and back to the original status if neither of the decision's criteria are met. Then set a scheduled bulk action to automate this action every day to check the status of the attached problem. As i have been informed that a condtion is only evaluated when it first hits the status rather than when a linked object changes status, if that makes sense?

                               

                              When we have upgraded to 7.5 will this be possible with improved automatic actions following a pre-condition or would i still need this scheduled bulk action?

                               

                              Automatic actions following a precondition

                               

                               

                               

                              Previously, if you had a process where a status was followed by a precondition or decision, which was then

                              followed by an automatic action, the automatic action would not automatically run unless the precondition

                              was met when the status was first reached. This behaviour would typically be seen when the process was

                              logged by e-mail and the precondition could not be fulfilled because it required additional fields to be

                              completed in Service Desk.

                              From 7.5, each time a process is updated, Service Desk tests any conditions that follow the current status

                              to see whether or not the conditions are met. If the conditions are met, then the automatic action runs.

                              This means that any automatic actions that follow a precondition or decision run as soon as the condition

                               

                              that they are based on is met.

                               

                               

                              • 12. Re: Process Design - Calculation on Status
                                Expert

                                When I look at the lines ....

                                 

                                static def GetAttributeValue(Incident):
                                
                                 Value = 'False'
                                
                                 Prob = Incident.IncidentProblem.Latest()
                                
                                 if Prob.Problem.Status.Title!='Investigating Root Cause Workaround Identified':
                                
                                

                                I see that you got the Attributes for Incident.  How did the problem attributes get opened?  Because there is a table that links incident to problem does it automatically open and link to Problem or does that need to be done in it's own getAttributeValue statement?  If problem attributes are not opened, Prob.Problem.Status.Title does not exist and might be returning your blank.  Is Incident.IncidentProblem.Latest returning a problem or the latest version of a problem?  A latest version could be a single number like 0,1, or 2 rather than the problem.  That would also mess up your Prob.Problem.Status.Title variable as it would not exist.
                                Unfortunately I do not know these answers but am facinated to see the answers.
                                • 13. Re: Process Design - Calculation on Status
                                  Expert

                                  Carl -

                                  You can get to the Problem attributes by following the path from Incident. Where I declared the variable Prob I followed the path from Incident to the Incident-Problem linking collection.

                                   

                                  Prob = Incident.IncidentProblem.Latest()
                                  

                                   

                                  From here I can then follow the patch to the Problem and it's attributes. The function Latest() simply picks the most recently created record in a collection.

                                   

                                  Adam -

                                  If you wanted to loop through each problem linked to an incident, and check each is not at a specific status, you could try something like this

                                   

                                  import System
                                  static def GetAttributeValue(Incident):
                                   Value = 'False'
                                   Prob = Incident.IncidentProblem
                                   ProbCount = Incident.IncidentProblem.Count
                                   inStatCount = 0
                                   for i in Prob:
                                    if i.Problem.Status.Title!='Investigating Root Cause Workaround Identified' and Prob.Problem.Status.Title!='Root Cause Identified Workaround Identified':
                                  
                                     inStatCount += 1
                                   next
                                   if ProbCount == inStatCount:
                                    Value = 'True'
                                   return Value
                                  

                                   

                                  This should then loop through each Problem linked to an incident and check that they're not in either of those statuses. If they're not it adds a 1 to the variable inStatCount. Once each problem has been checked it compares the number of Problems linked to the Incident with the number that are not in those statuses. If these values match (meaning no linked Problems are in those statuses) then it sets the value to True, otherwise it stays False.

                                   

                                  Cheers,

                                  Hadyn