11 Replies Latest reply on Jul 29, 2015 6:11 AM by noel.lester

    Calculation not working in Pre-Condition of Process

    noel.lester Employee

      I have a pre-condition in a process that I am trying to compare the Current User against the UPN in a filed on the request, to return a True or False value. below is the calculation code:

       

      import System

      static def GetAttributeValue(Request):

            Value = 'False'

            if Request.GetCurrentUserName() == Request._FolderPaths._ManagerUPN: Value = 'True'

            return Value

       

      I have tested this calculation on a temp attribute on the request and it returns a true and false value exactly as I need, yet it doesn't seem to operate when part of a process? I have the condition set to:

       

      Condition          Equals

      Value Type       Specific Value

      Value               True

       

      I am not sure why this is not working?

        • 1. Re: Calculation not working in Pre-Condition of Process
          ProServices

          try setting the value to 'true', see below...

           

          true and false i believe are normally represented as lower case

           

          • 2. Re: Calculation not working in Pre-Condition of Process
            noel.lester Employee

            Hi SBW

             

            Thanks for the prompt reply

             

            I have just updated the process pre-condition to:

             

            import System

            static def GetAttributeValue(Request):

                  Value = 'false'

                  if Request.GetCurrentUserName() == Request._FolderPaths._ManagerUPN: Value = 'true'

            return Value

             

            But it is still not showing me the action after the pre-condition. I did re-activate the process, and reset IIS aswell.

             

            Would it matter that the attribute Request._FolderPaths._ManagerUPN is being set by a scheduled calculation?

             

            Also I have read there are some restrictions with Process calculations, like you cannot use the 'CurrentUser' macro?

            • 3. Re: Calculation not working in Pre-Condition of Process
              ProServices

              Well if that calc to set the ManagerUPN isn't firing, it could be a problem...Though I'd think if it was null you might get an error...

               

              Is _FolderPaths a collection?

               

              edit:  Oh, and what serves me best in situations like this is to take this calculation and also create it as an attribute that I can see on my window.  That way you can see whats happening. or you can turn on diagnostic logging for calculations.

              • 4. Re: Calculation not working in Pre-Condition of Process
                noel.lester Employee

                Hi

                 

                I have a temp attribute on the Window, with the same calculation set (as an after read) and it's returning a 'true' value:

                 

                Capture.PNG

                 

                And when testing with another user, it's returning a 'false', so working as I want on the Window, but not in the Process.

                 

                _FolderPaths isn't a collection on Requests, just a one to one relationship. The FolderPaths object, does reside in System, rather than Requests, but as they are linked, and the calculation working, I don't think this is an issue.

                 

                The only thing I can think, is the GetCurrentUserName() function isn't working when inside a Process calculation?


                • 5. Re: Calculation not working in Pre-Condition of Process
                  SupportEmployee

                  Can you also try to use true and false without the single quotes in your code?

                   

                  Since you want to return a boolean you shouldn't need them.

                  • 6. Re: Calculation not working in Pre-Condition of Process
                    ProServices

                    One last thing to double check would be to adjust that window calculation to just return the string GetCurrentUserName() and make sure its what you're expecting for your comparison of ManagerUPN.  I would think it would be something similar to a SAMAccountName but I could be wrong.

                     

                    edit:  I found this comparison done by Andrew Swindells.  He's converting it with the ToLower() method first before his comparison.  Might be a good idea since a comparison is case sensitive.

                     

                    Re: Calculation: Get currently logged on user in Self Service Portal

                    • 7. Re: Calculation not working in Pre-Condition of Process
                      noel.lester Employee

                      Hi

                       

                      I have tried the return value with quotes, and without, also I've tried both variations with a capital T and F, and lowercase t and f.

                       

                      All to no difference.

                      • 8. Re: Calculation not working in Pre-Condition of Process
                        noel.lester Employee

                        Hi SBW

                         

                        I have an attribute using the same GetCurrentUserName() calcualtion at After Read, and it returns the UPN (universal principal name) of the end user on the Window. I also have another attribute on the window displaying the managers UPN, they both match, in case as well as characters. And when running the calculation on the Window, it works perfectly.

                         

                        It really makes no sense. There must be a difference/restriction in running this calculation in a process?

                         

                        I may have to goto LD Support for this one?

                         

                        Thanks

                        • 9. Re: Calculation not working in Pre-Condition of Process
                          Jamie Cannon ITSMMVPGroup

                          You may also want to make everything lower so that it'll make an exact match.  Something like:

                           

                          import System

                          static def GetAttributeValue(Request):

                                Value = 'false'

                                 UserName = Request.GetCurrentUserName().ToLower

                                if User == Request._FolderPaths._ManagerUPN.ToLower: Value = 'true'

                          return Value

                          • 10. Re: Calculation not working in Pre-Condition of Process
                            noel.lester Employee

                            HI

                             

                            Thanks for all of your replies.

                             

                            I have tried all of the above with no success.

                             

                            So I started doing some testing with a static value, rather than using the GetCurrentUserName() function, to ensure the comparison is working.

                             

                            I first tried this with a standard comparison, to compare the value in the attribute 'ManagersUPN' against a statically typed UPN, and worked as I wanted.

                             

                            When I then tried the same, in a calculation, it failed to work. So it would appear to be some issue in my calculation, comparing the ManagerUPN field to anything (static or otherwise).

                             

                            Thanks


                            Noel

                            • 11. Re: Calculation not working in Pre-Condition of Process
                              noel.lester Employee

                              OK, I have managed to resolve this.

                               

                              I have ended up using this calculation:

                               

                              import System

                              static def GetAttributeValue(Request):

                                    Value = 'NotManager'

                                    CurrentUser = Request.GetCurrentUserName()

                                    if CurrentUser == Request.CurrentAssignment.User.Name: return 'IsManager'

                              return Value

                               

                               

                              AND, the main reason it wasn't working before........................Priviledges. The relevant roles, didn't have access to the newly created action object. Yes, I feel a little silly, but it wasn't until I realised that the calculation was working for a manager who was an analyst that it hit me.

                               

                              Thanks again for all of your help.