Trigger PowerShell based SCSM workflow, based on value change of related item

STUSTU Member IT Monkey ✭

Hi Experts,

I need your advice. At a customer of mine (Cireson customer) I have created a custom SCSM workflow (using the Authoring Tool), which should trigger on property change of a related item (workflow trigger condition). To be more precise:

When the User Name of the Primary User of the Hardware Asset (Cireson Hardware Asset in use) changes, the workflow should trigger. Because I would like to trigger on any value change, i used the approach described here:

Workflow/Notification Subscription NotEqual Criteria Across Pre/Post Condition

which works perfectly fine when I am triggering the workflow on class property change, like for example:

OK Scenario:

                        <ValueExpression>
                          <Property State="Pre">$Context/Property[Type='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAsset']/Name$</Property>
                        </ValueExpression>
                        <Operator>NotEqual</Operator>
                        <ValueExpression>
                          <Property State="Post">$Context/Property[Type='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAsset']/Name$</Property>
                        </ValueExpression>

But when I am using a relationship (Cireson.AssetManagement.HardwareAssetHasPrimaryUser) the workflow does not fire at all:

NOTOK Scenario:

                        <ValueExpression>
                          <Property State="Pre">$Context/Path[Relationship='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAssetHasPrimaryUser' TypeConstraint='System!System.Domain.User']/Property[Type='System!System.Domain.User']/UserName$</Property>
                        </ValueExpression>
                        <Operator>NotEqual</Operator>
                        <ValueExpression>
                          <Property State="Post">$Context/Path[Relationship='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAssetHasPrimaryUser' TypeConstraint='System!System.Domain.User']/Property[Type='System!System.Domain.User']/UserName$</Property>
                        </ValueExpression>

In both cases (OK and NOT OK) the workflow and the trigger condition have been created with the Authoring Tool and then modified to fire on change from anything to anything else.

Does this approach work only for class property changes or it should work also for related item property changes?

Big thanks in advance for all the help!

Regards,

Stoyan

Best Answer

Answers

  • Brett_MoffettBrett_Moffett Cireson PACE Super IT Monkey ✭✭✭✭✭
    It looks like to me that your solution is using the wrong data projection for this to work.
    Using just the Hardware Asset class as the data projection will only return the data directly within the Hardware Asset class.
    If you used a wider data projection, like Hardware Asset (Advanced), it would contain all the related items that are related to the Hardware Asset.

    I've not done any authoring like this in the past but working from first principles this should be the case.
  • Brett_MoffettBrett_Moffett Cireson PACE Super IT Monkey ✭✭✭✭✭
    Nice catch! B)
  • STUSTU Member IT Monkey ✭
    Hey Brett,

    the approach works just fine if you add or change the Hardware Asset Primary User. The update of the value gets detetced by <AddRelationship>, because first the old relationship gets deleted and afterwards a new one is created. 

    But what about the deletion of the Primary User? I want to trigger the workflow on any change, this includes also the removal of the Primary User. Any ideas how I can solve this one?

    Again, many thanks in advance for your time. 

    Regards,
  • STUSTU Member IT Monkey ✭
    Here is an update on this one:

    There is the possibility to use <DeleteRelationship> and this will trigger the workflow on deletion, but will also introduce some complexity, because of the fact that the workflow will get triggered also on relationship update (rel gets deleted and then recreated). So in this case I will have to put the logic of checking for a deleted relationship within the PS script itself. 

    Hopefully this will be of help to someone dealing with the same challenge. 

    BR,
    Stoyan
  • Brett_MoffettBrett_Moffett Cireson PACE Super IT Monkey ✭✭✭✭✭
    Good idea @STU.
    Can you potentially use the DeleteRelationship to trigger a second workflow? Or is that just too much bother?
    I feel that the PowerShell option might be a better take on this as it could be more granular and take less steps to achieve.

    Keen to see the result and see how else people could use this in their environment to solve issues or business processes.
Sign In or Register to comment.