Skip to content

Code Run

Søren Granfeldt edited this page Nov 26, 2017 · 4 revisions

The Code Run activity allows you to write C# code which is compiled on the fly and executed. Your code can perform any task that can be written in code making this activity a regular hybrid. This activity can also update either WorkflowData or the object (Target) triggering the activity.

You can reference any number of .NET libraries in your code and the only requirement is that you have a class named FIMDynamicClass that contains a method called FIMDynamicFunction. You can have other classes besides this if so needed, but this specific class/method is the entry point that is called by the activity.

The function FIMDynamicFunction can return any type that you like, but mostly you would want to return either an object or a string for use for updating.

Activity Parameters

Parameter Description
Title This is the title of the current instance of the workflow. It is up to you to name this.
References Here you write the filenames of additional .NET libraries that your code needs. The file names can be typically found in C:\Windows\Microsoft.NET\Framework64\v2.0.50727
Parameters Specify any parameters that you want to pass to the FIMDynamicFunction method. The parameters are passed to the FIMDynamicFunction method in the order shown. Therefore, you should make sure that the function FIMDynamicFunction accepts the correct number of parameters and possible types. You can use XPath expression to resolve needed parameters, i.e. {"//Target/Manager/DisplayName"} or similar.
Code Write any C# code here. Just make sure that you have at least one class named FIMDynamicClass with a method named FIMDynamicFunction as this is the entrypoint called by the workflow.
Destination This is where you want the returned result of your code to be written. This could be the attribute of the object passed to the workflow (Target) or to the workflow library (WorkflowData) to be used in other activities. If your code returns NULL and the target's attribute has an existing value then that value is deleted. Note that no update is done if the existing value is the same as the new value.

Usage example

Below is a screenshot of an Code Run activity that does a rather simple regular expressions replacement of all numbers in the target's accountname with 'X'. And it updates the AccountName attribute of the target again with the new value. This may not be a really good practical real life example but it just shows how you could use this activity for very complex tasks that maybe could not be done with the built-in Function Evaluator.

The code from the sample above is shown below for completeness (please notice the class is called FIMDynamicClass and the method is called FIMDynamicFunction)

using System;
using System.Text.RegularExpressions;

public class FIMDynamicClass
{
    public object FIMDynamicFunction(object accountname, string pattern, string replacement)
    {
        return Regex.Replace((string)accountname, pattern, replacement, RegexOptions.IgnoreCase);
    }
}

You can see this page for more code samples.

Installing the Code Run Activity

You can install the Code Run Activity workflow by running the included PowerShell script 'Install-Workflows.ps1' with the parameter -CreateCodeActivity on the FIM Service server.

.\Install-Workflows.ps1 -CreateCodeRunActivity

You need to make sure that the user execute the installation command above, has the appropriate permissions in the FIM Service to be able create an Activity Information Configuration object and be able to put a new DLL in the Global Assembly Cache (GAC).

Clone this wiki locally