Using the If/Else Activity in the Authoring Tool
Published Feb 15 2019 07:27 AM 233 Views
First published on TECHNET on Jun 24, 2011

Let’s say you have a workflow that you want to behave differently based on the selection in a checkbox on a form.  If it is checked you want to do one thing. If it is not checked you want it to do another thing.  To do this you want to use the If/Else Windows Workflow Foundation activity provided out of the box in the SCSM Authoring Tool.  It’s not exactly obvious how to do this though so I’ll walk you through it end to end.

  1. First, start by launching the Service Manager Authoring Tool

  2. Create a new MP by clicking the New button in the toolbar or File –> New

  3. I’m going to name my MP ‘ Windows8Tablets ’ in honor of the really cool stuff that was demo’d recently re: Windows 8.

  4. Right click on Classes in the Management Pack explorer and choose ‘ Create Configuration Item Class…

  5. Give the Class the Name of Windows8Tablet and click Create .

  6. At the top of the class editor change the Class name from Windows8Tablet to Windows 8 Tablet and delete the description .

  7. Select the Property_4 that is automatically provided and delete it by clicking the red ‘X’ .  Click Yes on the confirmation dialog and OK on the warning dialog.  The warning dialog is telling you that your new class doesn’t have a key property.

  8. Click Create property… above the property list.

  9. Give the property a name of ID and click Create and then click OK again on the warning dialog.

  10. In the Details pane change Auto Increment to True , Key to True , and set the Default Value to {0} .

  11. Click Create property… again.

  12. This time name the property ‘ ForExecutive ’.

  13. In the Details pane, choose Bool from the Data Type drop down.  Set the Default Value to False

  14. Right click on Forms and choose Create .

  15. In the Base class dialog choose the ‘ Windows 8 Tablet ’ class and click OK .

  16. Give the form a name like Windows8TabletForm and click Create .

  17. Drag a label onto the form from the Form Customization Toolbox .

  18. Change the Content property to ID: in the Details pane.

  19. Drag another label onto the form and place it just below the ID: label.

  20. Change the Binding Path property in the Details pane by clicking the button and in the dialog that comes up choose the ID property (not the ID (Internal) property) and click OK .

  21. It should look like this:

  22. Drag a Check Box control from the toolbox onto the designer below the ID labels.

  23. Change the Content property to ‘ User is Executive ’.

  24. Change the Width property to 150.

  25. Change the Binding Path property by clicking the button and choosing the ForExecutive property and clicking OK .

  26. Right click on Workflows and choose Create .

  27. Give the workflow a name like ‘ NewWindows8TabletWorkflow ’ and click Next.

  28. Select the ‘ Run only when a database object meets specified conditions ’ since we want this workflow to be triggered each time a new Windows 8 Tablet object is created.

  29. Click Next .

  30. Click Browse… and choose the Windows 8 Tablet class and click OK .

  31. Click Next .

  32. Click Create .

  33. Click Close .

  34. Drag a PowerShell script activity onto the designer. This is the first part that is non-obvious but is the KEY to this working .  We need to get the properties of the object that triggered the workflow passed into the workflow as parameters.  One way to do this is to drop a meaningless PowerShell script activity into the workflow and bind it to some of the properties of the object.

  35. Select the PowerShell script activity .

  36. In the Details pane click the button next to the Script Parameters property

  37. In the Configure a Script Activity dialog click the New button to create a new script parameter.

  38. Name the parameter ForExecutive .

  39. Click the … button the same row to select the class property to bind to.

  40. In the dialog that comes up choose the ‘ Use a Class Property ’ radio button the left.

  41. Select the ForExecutive property from the list and click OK .

  42. Click the Script Body tab.

  43. In the script body tab enter the following script which will take the passed in value and simply write it to a file so we can see it:  $ForExecutive > C:\Input.txt

  44. Click OK .

  45. Drag an If/Else activity onto the designer from the toolbox.

  46. Drag a PowerShell script activity into each side of the If/Else activity.  These two activities will just simply simulate what you could do differently in each branch of the workflow.

  47. It should look like this:

  48. Now select the ifElseBranchActivity1 (the one on the left).  Over in the Details pane click the textbox next to the Condition property and choose Declarative Rule Condition from the drop down menu.

  49. Expand the plus sign to the left of the Condition property in the Details pane.

  50. Change the ConditionName property to IsTrue (this is just an arbitrary name, but I helps succinctly describe what the condition is so you don’t have to look inside at the formula).

  51. Click the button in the Expression property to bring up the Rule Condition Editor.  This is the second part that is non-obvious.

  52. Type this and then a period.  That will bring up a list of options.  Choose ‘windowsPowerShellScript1_ForExecutive.  Type another period and it will bring up more options.  Choose ToString then type an open and close paranthesis.  Then type a space, then two equals signed and then a space and then '”true”.

  53. It should look like this:

  54. Now, select the PowerShell script activity on the left and click the Script Body … button in the details pane.

  55. Enter the following script:  “This user is an executive” > C:\Result.txt

  56. It should look like this:

  57. Click OK

  58. Now repeat steps 48-57 for the right side except this time in the rule condition editor you will set the condition == “ false ” and you will set the script to say ‘This user is not an executive”.

  59. Save the MP using the toolbar button.

  60. Copy the .dll file from the folder where you created your MP to C:\Program Files\Microsoft System Center\Service Manager 2010 on the management server where your workflows are running.

  61. Import the MP .

  62. Go to the Configuration Items workspace in the console.

  63. Right click on Configuration Items and choose Create Folder.

  64. Give the Folder a name like Windows 8 Tablets and make sure the Windows8Tablets management pack is selected and click OK .

  65. Right click on the new Windows 8 Tablets folder that is created and choose Create View .

  66. Give the view a name like Windows 8 Tablets and then choose the Windows 8 Tablet class in the criteria section and click OK .

  67. In the new Windows 8 Tablets view click the task ‘ Create Windows 8 Tablet ’.

  68. The custom form should come up. Check the User Is an Executive checkbox and click OK .

  69. Open Windows Explorer on the management server where the workflows are running and navigate to the C: folder and wait for the .txt files to be created.

  70. Within less than a minute a new text file called C:\Input.txt will be created.  It should have the value ‘ true’ inside of it because the checkbox was checked.

  71. The file C:\Result.txt will have the value ‘ This user is an executive ’ in it.

  72. Now create another Windows 8 Tablet from the UI but this time make sure the checkbox is cleared and see what happens in the .txt files.

Version history
Last update:
‎Mar 11 2019 08:48 AM
Updated by: