Home Analyst Portal

APi GetProjectionByCriteria with Relationship assignedTo DisplayName

Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

Hi,

i dont get it to work. I want to query the API for all workitems from a user with some Relationships.

I created a Typeprojection and want to give the query the criteria "DisplayName" from the user. But i get an error.

Can someone give me a hint what i do wrong?

Query:

{

    "Id": "bad65e5c-7374-c596-3555-cd7c6b960b76",

    "Criteria": {

        "Base": {

          "Expression": {

            "SimpleExpression": {

              "ValueExpressionLeft": {

                "GenericProperty": "$Context/Path[Relationship='15e577a3-6bf9-6713-4eac-ba5a5b7c4722']/DisplayName$"

              },

              "Operator": "Equal",

              "ValueExpressionRight": {

                "Value": "UserDisplayName"

              }

            }

          }

        }

      }

    }



Error:

"Microsoft.EnterpriseManagement.Common.InvalidCriteriaException: The criteria could not be parsed. See inner exception for details.\r\n   at Microsoft.EnterpriseManagement.Common.ObjectProjectionCriteria.ValidateXmlCriteria(ReadOnlyCollection`1 propertyNames, ReadOnlyCollection`1 invalidCriteriaElements)\r\n   at Microsoft.EnterpriseManagement.Common.ObjectProjectionCriteria..ctor(String criteria, ManagementPackTypeProjection typeProjection, EnterpriseManagementGroup managementGroup)\r\n   at Cireson.ServiceManager.Services.Projection.<>c__DisplayClass11_0.<GetProjectionByCriteriaAsync>b__0(EnterpriseManagementGroup emg)\r\n   at Cireson.ServiceManager.ManagementService.ManagementService.InvokeCommand[T](Func`2 func, Boolean invokeAsService)\r\n   at System.Threading.Tasks.Task`1.InnerInvoke()\r\n   at System.Threading.Tasks.Task.Execute()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Cireson.ServiceManager.ManagementService.ManagementService.<InvokeCommandAsync>d__9`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at Cireson.ServiceManager.Services.Projection.<GetProjectionByCriteriaAsync>d__11.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at CiresonWebConsole.Controllers.api.V3.ProjectionController.<GetProjectionByCriteria>d__9.MoveNext() in D:\\a\\1\\s\\Cireson.WebConsole\\Cireson.ServiceManager.WebConsole\\Controllers\\api\\V3\\ProjectionController.cs:line 86\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()"

Best Answers

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓

    HI @Jan_Schulz Of course, so to be honest with you, the way we figured this out the end was from the Newtonsoft Documentation.

    But to make this simple, before when you were using a property you would have:

    "Property":"$Context/Property[Type='c0c58e7f-7865-55cc-4600-753305b9be64']/HardwareAssetID$""

    When you use a Generic Property the syntax changes, you would use this when you want to use a relationship:

    "GenericProperty": {

                  "@Path": "$Context/Path[Relationship='15e577a3-6bf9-6713-4eac-ba5a5b7c4722']$",

                  "#text": "DisplayName"

                }

    As you can see the different is.. The path that you are using to get to the property stays as the path with the $ sign at the end.

    Then the property you want from that relationship is what you put in text. Therefore if you wanted username you would do this instead:

    "GenericProperty": {

                  "@Path": "$Context/Path[Relationship='15e577a3-6bf9-6713-4eac-ba5a5b7c4722']$",

                  "#text": "Username"

                }

    Hope this helps Jan!

    Thanks,

    Shane

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓

    The below should work for you, the best advice I can give, build the criteria in the Cireson View Builder, and look at the XML then convert to JSON:

    {

        "Id": "62bc2bc9-14be-3ff9-1ff4-ba3e0930f03c",

        "Criteria": {

            "Base": {

                "Expression": {

                    "SimpleExpression": {

                        "ValueExpressionLeft": {

                           "Property":"$Context/Path[Relationship='15e577a3-6bf9-6713-4eac-ba5a5b7c4722' TypeConstraint='eca3c52a-f273-5cdc-f165-3eb95a2b26cf']/Property[Type='eca3c52a-f273-5cdc-f165-3eb95a2b26cf']/UserName$"

                        },

                        "Operator": "Like",

                        "ValueExpressionRight": {

                            "Value": "Shane%"

                        }

                    }

                }

            }

        }

    }

Answers

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭

    Hi Jan,

    Hope you are well.

    So when you are using a GenericProperty the syntax is slightly different, you need to do something like this:


    {

      "Id": "62bc2bc9-14be-3ff9-1ff4-ba3e0930f03c",

      "Criteria": {

        "Base": {

          "Expression": {

            "SimpleExpression": {

              "ValueExpressionLeft": {

                "GenericProperty": {

                  "@Path": "$Context/Path[Relationship='15e577a3-6bf9-6713-4eac-ba5a5b7c4722']$",

                  "#text": "DisplayName"

                }

              },

              "Operator": "Like",

              "ValueExpressionRight": {

                "Value": "Shane%"

              }

            }

          }

        }

      }

    }


    Let me know if this helps!

    Thanks,

    Shane

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

    @Shane_White yes thank you for that.

    But how could i find the word for example @Path and #text. Where can i find such information?

    How would you filter not the DisplayName of a user but a username?

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓

    HI @Jan_Schulz Of course, so to be honest with you, the way we figured this out the end was from the Newtonsoft Documentation.

    But to make this simple, before when you were using a property you would have:

    "Property":"$Context/Property[Type='c0c58e7f-7865-55cc-4600-753305b9be64']/HardwareAssetID$""

    When you use a Generic Property the syntax changes, you would use this when you want to use a relationship:

    "GenericProperty": {

                  "@Path": "$Context/Path[Relationship='15e577a3-6bf9-6713-4eac-ba5a5b7c4722']$",

                  "#text": "DisplayName"

                }

    As you can see the different is.. The path that you are using to get to the property stays as the path with the $ sign at the end.

    Then the property you want from that relationship is what you put in text. Therefore if you wanted username you would do this instead:

    "GenericProperty": {

                  "@Path": "$Context/Path[Relationship='15e577a3-6bf9-6713-4eac-ba5a5b7c4722']$",

                  "#text": "Username"

                }

    Hope this helps Jan!

    Thanks,

    Shane

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

    @Shane_White thank you for the hints.

    But unfortunatelly the example with the Username instead of DisplayName dont work for me. I get an exception that the criteria is wrong

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓

    The below should work for you, the best advice I can give, build the criteria in the Cireson View Builder, and look at the XML then convert to JSON:

    {

        "Id": "62bc2bc9-14be-3ff9-1ff4-ba3e0930f03c",

        "Criteria": {

            "Base": {

                "Expression": {

                    "SimpleExpression": {

                        "ValueExpressionLeft": {

                           "Property":"$Context/Path[Relationship='15e577a3-6bf9-6713-4eac-ba5a5b7c4722' TypeConstraint='eca3c52a-f273-5cdc-f165-3eb95a2b26cf']/Property[Type='eca3c52a-f273-5cdc-f165-3eb95a2b26cf']/UserName$"

                        },

                        "Operator": "Like",

                        "ValueExpressionRight": {

                            "Value": "Shane%"

                        }

                    }

                }

            }

        }

    }

  • Jan_SchulzJan_Schulz Customer Adept IT Monkey ✭✭

    @Shane_White thank you.

    Last question :-)

    Which converter from xml to json do you use?

  • Shane_WhiteShane_White Cireson Support Super IT Monkey ✭✭✭✭✭

    My brain :-P I use examples that worked previously and adjust based on what I see in the XML criteria.

    But you I did play around with this one:

    Just sometimes it doesn't change it perfectly!

Sign In or Register to comment.