0

I am developing a workflow as a part of Visual Studio full trust solution. In the workflow I have used GetConfigurationValue activity. Configuration value is defined in appropriate Elements.xml file:

<Property Name="DrugiStupanjPukId" Value="{$ListId:Lists/DrugiStupanjPuk;}" />

This workflow is associated to 2 lists. On the first list this activity executes without a problem.

However, on the second list when workflow execution reaches this activity, an exception is raised:

System.InvalidOperationException: Configuration 'DrugiStupanjPukId' was not found and a default value was not specified. at Microsoft.Activities.GetConfigurationValue.Execute(CodeActivityContext context) at System.Activities.CodeActivity`1.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

How do I resolve this issue?

0

I found out what was the problem with the second list and resolved this issue, so I'm posting a solution for future reference.

Workflow association to the first list was defined in Elements.xml file while second workflow association was defined programmatically in feature receiver using Microsoft.SharePoint.Client.WorkflowServices library. All I needed to do was to add missing configuration properties programmatically.

Setting configuration properties programmatically is done by calling WorkflowSubscription.SetProperty method. Complete code snippet which resolved the issue:

public static void AssociateWfTemplateToList(
    string siteUrl, 
    string templateWfName, 
    string newWfSubscriptionName, 
    Guid targetListGuid,
    List<string> events,
    NameValueCollection configurationProperties) {
    using (ClientContext clientContext = new ClientContext(siteUrl)) {

        //Workflow Services Manager which will handle all the workflow interaction.
        WorkflowServicesManager wfServicesManager = new WorkflowServicesManager(clientContext, clientContext.Web);

        //Deployment Service which holds all the Workflow Definitions deployed to the site
        WorkflowDeploymentService wfDeploymentService = wfServicesManager.GetWorkflowDeploymentService();

        //Get all the definitions from the Deployment Service, or get a specific definition using the GetDefinition method.
        WorkflowDefinitionCollection wfDefinitions = wfDeploymentService.EnumerateDefinitions(false);

        clientContext.Load(wfDefinitions, wfDefs => wfDefs.Where(wfd => wfd.DisplayName == templateWfName));
        clientContext.ExecuteQuery();

        WorkflowDefinition wfDefinition = wfDefinitions.First();

        //The Subscription service is used to get all the Associations currently on the SPSite
        WorkflowSubscriptionService wfSubscriptionService = wfServicesManager.GetWorkflowSubscriptionService();

        //The subscription (association)
        WorkflowSubscription wfSubscription = new WorkflowSubscription(clientContext);
        wfSubscription.DefinitionId = wfDefinition.Id;
        wfSubscription.Enabled = true;
        wfSubscription.Name = newWfSubscriptionName;

        // set the workflow start settings
        wfSubscription.EventTypes = events;

        // set the associated configuration properties
        foreach (string key in configurationProperties)
        {
            wfSubscription.SetProperty(key, configurationProperties[key]);
        }

        //Create the Association
        wfSubscriptionService.PublishSubscriptionForList(wfSubscription, targetListGuid);

        clientContext.ExecuteQuery();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.