none
Error when running wrokflow that is created by code RRS feed

  • Question

  • Hello,

    •  I have add "Publish approval" workflow to content type by the following code .
    • The work flow added successfully.
    • I go to list . and add new Item . then Run the work flow manually .
    • The work flow canceld . And check the history  "Coercion Failed: Input cannot be null for this coercion."

    private static void AddWorkFlowToContenTType(SPSite site ,SPWeb web,SPContentType contenTType)
            {
                SPList workFlowTasks = web.Lists["Workflow Tasks"];
                 SPList historyList = web.Lists["Workflow History2"];

                SPWorkflowTemplate wflTemplate = site.RootWeb.WorkflowTemplates.GetTemplateByName("Publishing Approval", System.Globalization.CultureInfo.CurrentCulture);

                SPWorkflowAssociation wflAss = SPWorkflowAssociation.CreateListAssociation(wflTemplate, "Submit for approval", workFlowTasks, historyList);
                wflAss.AutoStartChange = false;
                wflAss.AutoStartCreate = false;
                wflAss.AllowManual = true;
                wflAss.AssociationData = GetApprovalWorkFlowData();

                web.AllowUnsafeUpdates = true;
                contenTType.WorkflowAssociations.Add(wflAss);
                contenTType.Update(true);
                web.AllowUnsafeUpdates = false;
            }

     private static string GetApprovalWorkFlowData()
            {
               string result =@"<dfs:myFields xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:dms='http://schemas.microsoft.com/office/2009/documentManagement/types' xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:q='http://schemas.microsoft.com/office/infopath/2009/WSSList/queryFields' xmlns:d='http://schemas.microsoft.com/office/infopath/2009/WSSList/dataFields' xmlns:ma='http://schemas.microsoft.com/office/2009/metadata/properties/metaAttributes' xmlns:pc='http://schemas.microsoft.com/office/infopath/2007/PartnerControls' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
                          <dfs:queryFields></dfs:queryFields>
                          <dfs:dataFields>
                            <d:SharePointListItem_RW>
                              <d:Approvers>
                                <d:Assignment>
                                  <d:Assignee>
                                    <pc:Person>
                                      <pc:DisplayName>DhofarApprover</pc:DisplayName>
                                      <pc:AccountId>DhofarApprover</pc:AccountId>
                                      <pc:AccountType>SharePointGroup</pc:AccountType>
                                    </pc:Person>
                                  </d:Assignee>
                                  <d:Stage xsi:nil='true' />
                                  <d:AssignmentType>Serial</d:AssignmentType>
                                </d:Assignment>
                              </d:Approvers>
                              <d:ExpandGroups>false</d:ExpandGroups>
                              <d:NotificationMessage />
                              <d:DueDateforAllTasks xsi:nil='true' />
                              <d:DurationforSerialTasks xsi:nil='true' />
                              <d:DurationUnits>Day</d:DurationUnits>
                              <d:CancelonRejection>false</d:CancelonRejection>
                              <d:CancelonChange>false</d:CancelonChange>
                              <d:EnableContentApproval>true</d:EnableContentApproval>
                            </d:SharePointListItem_RW>
                          </dfs:dataFields>
                        </dfs:myFields>";

                return result;
            }

    So what is wrong ?


    ASk

    Monday, May 26, 2014 11:51 AM

Answers