Trigger PowerShell based SCSM workflow, based on value change of related item
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:
<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
-
STU Member IT Monkey ✭Hi,
with a bit of help I've managed to get it working. The specific thing here was that when the Primary User of the Hardware Asset is updated the whole relationshipRelType="$MPElement[Name='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAssetHasPrimaryUser']$" SourceType="$MPElement[Name='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAsset']$" TargetType="$MPElement[Name='System!System.Domain.User']$"
gets deleted and recreated. So basically, what I did was:
I've replaced<InstanceSubscription Type="$MPElement[Name='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAsset']$"> <UpdateInstance> <Criteria> <Expression> <SimpleExpression> <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> </SimpleExpression> </Expression> </Criteria> </UpdateInstance>
with this:
<RelationshipSubscription RelType="$MPElement[Name='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAssetHasPrimaryUser']$" SourceType="$MPElement[Name='CustomCiresonAssetManagement!Cireson.AssetManagement.HardwareAsset']$" TargetType="$MPElement[Name='System!System.Domain.User']$"> <AddRelationship /> </RelationshipSubscription>
so that instead of working with proiperty value changes I work with Relationship Subscription.
The workflow gets triggered now
Many thanks for all the efforts.
Regards,
Stoyan
6
Answers
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.
with a bit of help I've managed to get it working. The specific thing here was that when the Primary User of the Hardware Asset is updated the whole relationship
gets deleted and recreated. So basically, what I did was:
I've replaced
with this:
so that instead of working with proiperty value changes I work with Relationship Subscription.
The workflow gets triggered now
Many thanks for all the efforts.
Regards,
Stoyan
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,
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
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.