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:

                <AssemblyName>Cireson.Powershell.Activity.Workflow</AssemblyName>
                <WorkflowTypeName>Cireson.Powershell.Activity.Workflow.RunPowershellScript</WorkflowTypeName>
		<WorkflowParameters>
		</WorkflowArrayParameter>
                  <WorkflowArrayParameter Name="InstanceId" Type="guid">
                    <Item>284ce973-3422-7e7f-4bf0-b558c187190f</Item>
                  </WorkflowArrayParameter>                
			</WorkflowParameters>

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?

Answers

  • 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.

    Geoff

  • 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

  • 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...

    Geoff

  • Eric_EvansEric_Evans Member IT Monkey ✭
    edited September 2021

    @Geoff_Ross

    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.

  • 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?

  • 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.

  • 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:

    <WriteActions>
      <WriteAction ID="WA" TypeID="Subscriptions!Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction">
        <Subscription>
          <VisibleWorkflowStatusUi>true</VisibleWorkflowStatusUi>
          <EnableBatchProcessing>true</EnableBatchProcessing>
          <WindowsWorkflowConfiguration>
            <AssemblyName>Cireson.ExecutePowerShell</AssemblyName>
            <WorkflowTypeName>Cireson.ExecutePowerShell.Workflow.ExecutePowershell</WorkflowTypeName>
            <WorkflowParameters>
              <WorkflowArrayParameter Name="InstanceIds" Type="guid">
                <Item>$Data/BaseManagedEntityId$</Item>
              </WorkflowArrayParameter>
              <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>
            </WorkflowParameters>
            <RetryExceptions />
            <RetryDelaySeconds>60</RetryDelaySeconds>
            <MaximumRunningTimeSeconds>7200</MaximumRunningTimeSeconds>
          </WindowsWorkflowConfiguration>
        </Subscription>
      </WriteAction>
    </WriteActions>
    
Sign In or Register to comment.