9 Replies Latest reply on Mar 4, 2016 8:44 AM by cgodden

    Populate Task - Details from Request data

    Apprentice

      Hello,


      We have a couple Request Processes that need to spawn Tasks for associated items, such as Cell Phone set up or Computer set up.

       

      I need to pass request details from the Request to the Task since they are handled by different Groups and the Task owner may not have visibility to the Request itself.

       

      I found a discussion - http://community.landesk.com/support/message/70450#70450 which I thought might solve my issue, but I am having trouble getting execution correct.  It uses a Calculation in the Task Details.

       

      In the most basic form the Caculation will work but when I try to get it to provide anything additional or more complete it fails and the Task Details are blank.

       

      For example -- This small test works and populates the Task Details with the work "Test".

      import System

      static def GetAttributeValue(Process):

      return String.Format ("Test")

       

      For example -- This single variable test worked and populated the Task Details with "Computer Required - True".

      import System

      static def GetAttributeValue(Process):

      return String.Format ("Computer Required - {0}",Process.Request._Computer)

       

      These all fail to put any content in Task Details (Syntax check passes).

      import System

      static def GetAttributeValue(Process):

      return String.Format ("Associated Request ID- {0}",Process.Request._newref)

      return String.Format ("First Name - {0}",Process.Request._ADGivenName)

      return String.Format ("Middle Name - {0}",Process.Request._MiddleName)

      return String.Format ("Last Name- {0}",Process.Request._ADSurname)

      return String.Format ("Computer Required - {0}",Process.Request._Computer)

       

      import System

      static def GetAttributeValue(Process):

      return String.Format ("Associated Request ID- {0}.  First Name - {1}.  Middle Name - {2}.  Last Name- {3}.  Computer Required - {4}. ", Process.Request._newref, Process.Request._ADGivenName, Process.Request._MiddleName, Process.Request._ADSurname, Process.Request._Computer)

       

      import System

      static def GetAttributeValue(Process):

      return String.Format ("New Hire Information -- First Name - {0}.  Middle Name - {1}.  Last Name- {2}.  Computer Required - {3}. ",Process.Request._ADGivenName, Process.Request._MiddleName, Process.Request._ADSurname, Process.Request._Computer)


      So I don't know if I have a code issue here or if I'm using incorrect attributes or...?

       

      Any ideas are appreciated.

      Thanks

        • 1. Re: Populate Task - Details from Request data
          Expert

          I had similar problems when I was setting up some child tasks in the Request Management module (coincidence...?).  In the end, I gave up trying to work out why my calculations were not working, and ended up putting a "Set Value" automatic action early in the my Task process designs which would set the values that I wanted.

          • 2. Re: Populate Task - Details from Request data
            Apprentice

            Thanks Paul - I may give that a shot instead.

             

            I have got this one working (there was a typo):

            import System

            static def GetAttributeValue(Process):

            return String.Format ("New Hire Information -- First Name - {0}.  Middle Name - {1}.  Last Name- {2}.  Computer Required - {3}. ",Process.Request._ADGivenName, Process.Request._MiddleName, Process.Request._ADSurname, Process.Request._Computer

             

            Unfortunately it isn't smart enough to ignore Null values (middle name is optional).

             

            So I started down the path of using checking for Null values based on a sample I found here and have had little success...

             

            import System

            static def GetAttributeValue(Incident):

                      TheCustomer = ''

                      if Incident.Customer != null: TheCustomer = Incident.Customer.Title

             

                      TheCategory = ''

                      if Incident.Category != null: TheCategory = Incident.Category.FullName

             

                      TheResponseLevel = ''

                      if Incident.ResponseLevel != null: TheResponseLevel = Incident.ResponseLevel.Title

             

                      TheOwner = ''

                      if Incident.CurrentAssignment != null:

                                if Incident.CurrentAssignment.User != null:

                                          TheOwner = Incident.CurrentAssignment.User.Title

             

                      Value = 'Customer: ' + TheCustomer

                      Value += '\r\n Category: ' + TheCategory

                      Value += '\r\n Response Level: ' + TheResponseLevel

                      Value += '\r\n Incident Owner: ' + TheOwner

                      return Value

             

            I've simplified to a single section for just "First Name" and it still fails.

             

            Good times.

            • 3. Re: Populate Task - Details from Request data
              Apprentice

              Hi Paul,

              Can you give me any additional details on your method?  Looking at adding an Auto Action Instance to my Task, essentially puts me in the same place.  There is no way to fill the Task Window Details field without a calculation.

               

              I've had minimal luck using the calculations so far and seen such erratic behaviour that I would almost hate to put it in production.  For example - Test with Calc_1 and it works, add to it to create Calc_2 and it fails, revert to Calc_1 and it fails.  The exact same code works and then fails...  Another example - Calc_1 works, create a new Calc_2 from scratch, the system continues to output Calc_1 values.  FYI - I am deactivating, modifying, saving, and activating every time.

               

              Thanks

              • 4. Re: Populate Task - Details from Request data
                Apprentice

                Posting this in case it might help someone sometime...

                 

                All comments are purely my experience - no promises, guarantees, etc.  If I were to describe this process, "flakey" would be the one word.  See my previous post for a couple examples of strange things I saw.

                 

                I finally got this to work - passing values from the Request to the Task Details.  But I'm still not satisfied as it didn't completely work.

                 

                Some of the attributes I was trying to copy/display in the Task Details:

                • Process.Request._ADGivenname
                • Process.Request._MiddleName
                • Process.Request._ADSurname
                • Process.Request._Computer
                • Process.Request._Printer
                • Process.Request._Department
                • Process.Request._RequestedBy

                 

                Computer and Printer are Boolean values, default to False.  I found that the booleans didn't like the NULL check process and would simply fail if I used it as documented.

                 

                I was unable to get any output for _Department or _RequestedBy.  I tried going super simple and still could not get any output.  I gave up on these attributes.(EDIT -- Found that items that I'm having issues with are Objects using Reference Lists, not Attributes.  More reasearch...)

                import System

                     static def GetAttributeValue(Process):

                     Value = Process.Request._Department

                     return Value

                 

                In the end I removed the NULL checks for attributes that were mandatory in my form and the booleans which have default values set.  I don't know if it was just luck, but I used Microsoft C# for the date string and it works.

                 

                import System

                static def GetAttributeValue(Process):

                    FN = Process.Request._ADGivenname

                    MN = ' '

                    if Process.Request._MiddleName != null: MN = Process.Request._MiddleName

                    LN = Process.Request._ADSurname

                    Title = Process.Request._JobTitle

                    VPN = Process.Request._VPN

                    HireDate = Process.Request._EffectiveDate.Date

                    OutDate = HireDate.ToString("MM/dd/yyyy")

                    Desc = ' '

                    if Process.Request.Description != null: Desc = Process.Request.Description

                    Value = ' New Hire: ' + FN + ' ' + MN + ' ' + LN

                    Value += '\n Title: ' + Title

                    Value += '\n Hire Date: ' + OutDate

                    Value += '\n Test SSL VPN: ' + VPN

                    Value += '\n Additional requirements below: '

                    Value += '\n' + Desc

                    return Value

                • 5. Re: Populate Task - Details from Request data
                  Expert

                  Hi Tim

                   

                  Calculations do not handle null values very well - in general the first thing you need to do is to have a whole bunch of "if" statements checking if a value is null, and only procede to use that value if it isn't.

                   

                  Re your RequestedBy and Department attribute problems - did you try using attributes like _RequestedBy\Title instead?

                   

                  Cheers


                  Paul

                  • 6. Re: Populate Task - Details from Request data
                    Apprentice

                    Paul,

                     

                    I was fortunate in that most of my values were requried or defaulted to False in the case of the booleans.  The only one that was not mandatory was MiddleName and I ended up setting it as a blank space and then writing the actual value if not NULL.  The code above is working.

                     

                    I didn't try "_RequestedBy\Title".  I've been focusing on the Department item.  I have two other items that are using drop down menus with Reference Lists in the Request Window that I need to get data from and into Tasks.  I found that the method I am using above is working for Attributes, but fails anytime the item is using a Reference List. 

                     

                    I've also just started trying to repeat this when creating a secondary Request from the Primary Request.  My code isn't working, but I have a feeling that it is because I am missing something to tell it to use the Parent Request.

                     

                    Thanks again

                    • 7. Re: Populate Task - Details from Request data
                      Expert

                      If working with lists, I've always found it better to specify the actual attribute you wish to use, such as "Title", so it would be _RequestedBy.Title and _Department.Title (or similar).

                       

                      As far as working with the Parent Request, that can also be a little different as you are now working with a collection object (as there can be multiple parents (which does seem a bit strange in itself)) - I've always used a loop to access those items.

                      1 of 1 people found this helpful
                      • 8. Re: Populate Task - Details from Request data
                        Apprentice

                        Paul,

                         

                        Your last two notes put me on the right track.  I was concentrating on the Request Object, but had to look at the System Object for the Reference List to get the remainder of the string.  My last attribute as _Title.

                         

                        Thanks

                        • 9. Re: Populate Task - Details from Request data
                          Specialist

                          We are trying to do the same thing on indents but have not had any luck with our calculations. Any one have a simple one that just shows the raise user, incident reference number and subject?