Skip to content

How it’s works: token [mygroups]

How it’s works: token [mygroups] published on 3 Comments on How it’s works: token [mygroups]

With SCSM 2012 (SP1 and R2) we can use three different tokens: [now], [me] and [mygroups]. If two of them are simple and already described (here small help about [now]), than [mygroups] is more complex and required some explanation.

The [mygroups] allow you to search object of Microsoft.AD.UserBase class (or any derived) by groups where current user is member of.

First of all, you can use [mygroups] token only with <In> expression. Unfortunately, you can’t create this expression using UI. The basic template for <In> expression is:

<Expression>
  <In>
    %PROPERTY%
    <Values>
      <Token></Token>
      <Value></Value>
    </Values>
  </In>
</Expression>

You can use only <Token>, or only <Value> or both. You can use any property for <In> expression, but as soon as we talk about [mygroups] token we only property that we can use is Id (internal object ID). This is generic property, so we must use <GenericProperty> element. The full syntax is depend from is we want to search object itself (in other words “get group where I member”). In this case syntax is very simple:

<Expression>
  <In>
    <GenericProperty>Id</GenericProperty>
    <Values>
      <Token>[mygroups]</Token>
    </Values>
  </In>
</Expression>

Also you can search by relationship (“get incidents where assigned to is group where I member”). In this case you must add Path attribute:

<Expression>
  <In>
    <GenericProperty Path="$Context/Path[Relationship='WorkItem!System.WorkItemAssignedTo']$">Id</GenericProperty>
    <Values>
      <Token>[mygroups]</Token>
    </Values>
  </In>
</Expression>

Please note: in notation below I’m using management pack-specified syntax (note to WorkItem! alias). This means that you must specified management pack alias in your query or run query against management pack with same alias defined in. If you want to use management pack-independed version then just replace “WorkItem!System.WorkItemAssignedTo” with Id of the relationship:

<Expression>
  <In>
    <GenericProperty Path="$Context/Path[Relationship='dff9be66-38b0-b6d6-6144-a412a3ebd4ce']$">Id</GenericProperty>
    <Values>
      <Token>[mygroups]</Token>
    </Values>
  </In>
</Expression>

Here is the code snippet (PowerShell) to get all incident where affected user is group which current user is member of:

$exp = "<Criteria  xmlns='http://Microsoft.EnterpriseManagement.Core.Criteria/'>
  <Reference Id='System.WorkItem.Library' Version='7.5.1561.0' PublicKeyToken='31bf3856ad364e35' Alias='WorkItem' />
  <Reference Id='System.Library' Version='7.5.1561.0' PublicKeyToken='31bf3856ad364e35' Alias='System' />
    <Expression>
        <In>
        <GenericProperty Path=`"`$Context/Path[Relationship='dff9be66-38b0-b6d6-6144-a412a3ebd4ce']$`">Id</GenericProperty>
        <Values>
            <Token>[mygroups]</Token>
        </Values>
        </In>
      </Expression>
</Criteria>"

$mg = Get-SCSMSession
$tp = Get-SCSMTypeProjection "System.WorkItem.Incident.View.ProjectionType$"

try
{
    $cr = New-Object Microsoft.EnterpriseManagement.Common.ObjectProjectionCriteria([string]$exp2, 
[Microsoft.EnterpriseManagement.Configuration.ManagementPackTypeProjection]$tp, 
[Microsoft.EnterpriseManagement.EnterpriseManagementGroup]$mg)
}
catch{
    #if something wrong with your criteria we nned to know what exactly
    $_.Exception.InnerException.InnerException
}
Get-SCSMObjectProjection -Criteria $cr

But how is it works? Behind the scene, the SDK get all groups for current user by calling method  GetConnectedUserAdGroups() of the EnterpriseManagementGroup class instance. This method return ID of the all groups for current user:

image

After that the SDK will replace <Token>[mygroups]</Token> to real <Value> element for each of founded  ID. In other words, the expression

<Expression>
  <In>
    <GenericProperty Path="$Context/Path[Relationship='dff9be66-38b0-b6d6-6144-a412a3ebd4ce']$">Id</GenericProperty>
    <Values>
      <Token>[mygroups]</Token>
    </Values>
  </In>
</Expression>

will changed to:

<Expression>
  <In>
    <GenericProperty Path="$Context/Path[Relationship='dff9be66-38b0-b6d6-6144-a412a3ebd4ce']$">Id</GenericProperty>
    <Values>
      <Value>cbe28dc7-020b-270c-d2cb-090458096d2f</Value>
      <Value>36833d4b-652e-ea68-1d37-0caece9ab731</Value>
      <Value>05fc5886-2027-8cd6-1357-3a852266eaff</Value>
      <Value>dd3828ae-2d4a-9647-97bd-3a9b287bb2d8</Value>
      <Value>f577217a-fd23-cf8a-b4e9-6d2250ce6c4f</Value>
      <Value>b20930b3-e72e-81ce-343a-863404b0f4c6</Value>
      <Value>b49de142-098c-3d7d-9a55-b9831186d7e0</Value>
      <Value>9ac20760-dc08-ae6b-1776-c3fc3e0446cb</Value>
      <Value>690594f5-b07d-37a6-0964-feed55aa5f50</Value>
    </Values>
  </In>
</Expression>

Share

3 Comments

Leave a Reply to SCSMUS Cancel reply

Primary Sidebar

%d bloggers like this: