Home Service Manager

Issue with powershell script in workflow.

Eric_EvansEric_Evans Member IT Monkey ✭

I have a script I would like run when a workitem is changed. I am able to trigger the work flow correctly, and I can get the script to run by running an instance:

                  <WorkflowArrayParameter Name="InstanceId" Type="guid">

However this just runs that instance and doesn't change parameters based on the workitem. I tried to replace "InstanceId" with just "Id" to no avail. Is there a way that I can run the actual script and not just a certain instance of it?


  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.

    Wow @Eric_Evans

    Your question has blown my mind. I'm not even sure how this works but I love your thinking. I'm going to investigate tomorrow.


  • Options
    Eric_EvansEric_Evans Member IT Monkey ✭

    Haha well, be careful, I have been down this rabbit hole all day.

    I'll let you know IF I get anywhere

  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.

    Hi @Eric_Evans

    The workflow is designed to take the Id of a PowerShell Activity object, read the related script and figure out the params based on the context of where the Activity sits.

    What you are trying to do is genius, but sadly not possible. Yet...


  • Options
    Eric_EvansEric_Evans Member IT Monkey ✭
    edited September 2021


    Thank you so much for the kind words. I have figured out a way to do what I need (in theory) I have yet to make a proof of concept (hope to tonight). Here is the idea:

    1.    Make a template that has predefined parameters.

    2.    Make a workflow that when a condition is met (Priority = Medium) the template will be applied.

    3.    Make a workflow with a script that will search for those parameters and pull in the information. once you have the information, you are free to what you wish. After you do what you need to do, have the script to set the work item’s template back to the original.

    This workaround will take some time to build out, but I do think it will work for what I need. Also, this idea will not work for more than one work item at a time (since the whole thing hinges on finding that unique factor in the template), if more than one work item has that factor set, it might not get the right information.

  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.

    What if there was a separate custom workflow that took three parameter

    1. The Guid of the PS Script
    2. The Guid of the object that triggered the workflow (eg an IR)
    3. The name of the Param in the PS that should receive the Guid from 2. eg "IRGuid"

    Then as long as your Param matches on the PS:

    Param ($IRGuid)

    Then you can read the rest of the properties from the IR in the PS.

    Does that sound interesting?

  • Options
    Eric_EvansEric_Evans Member IT Monkey ✭

    @Geoff_Ross I am sorry, priorities have led me elsewhere at this time. I hope to revisit this idea soon thank you for your help so far.

  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.

    Hey Eric,

    I remembered this thread when I saw your name pop up. I have a solution here if you want to have a play?

    Place this DLL in your ServiceManager installation folder and then you can use it in your custom workflow MP.

    Replace your Write Action as follows:

      <WriteAction ID="WA" TypeID="Subscriptions!Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction">
              <WorkflowArrayParameter Name="InstanceIds" Type="guid">
              <WorkflowParameter Name="WorkItemParam" Type="string">{{Name of the param in your script that the BaseId will be passed into eg. IRGuid}}</WorkflowParameter>
              <WorkflowParameter Name="PSScriptId" Type="guid">{{Guid of the PowerShell Script Object}}</WorkflowParameter>
            <RetryExceptions />
Sign In or Register to comment.