Tag Archive | Workflow

Saving Custom Task Form In Sharepoint Workflow

I have encountered a situation of saving the custom task form(Infopath) in workflow, the challenge here was to maintain the persistence of the data entered by the users, so that they can view the data saved when opened for the next time.

This is how i achieved it .

1. Add fields to be saved in ItemMetaData file .For eg if Comments is the field to be saved add this line in ItemMetaData file.

<z:row xmlns:z=”#RowsetSchema” ows_Comments_=””/>

2. Assign ows_Comments as the default value for the Comments fields. (check Secondary data source to assign).

3. Add Save Button .

4. Add rule to the button .(Add Submit connection and Submit data using the connection).

5. Add UpdateTask activity on completion of  OnTaskChanged in workflow.cs file.

6. Declare a variable called approverComments in workflow.cs source file .

7. Assign approverComments in onTaskChanged method,

if (On_Task_Changed_AfterProperties.ExtendedProperties[“Comments”] != null)
approverComments = On_Task_Changed_AfterProperties.ExtendedProperties[“Comments”].ToString();

This will get the Comments entered by the approver and assigns to a variable.

8. Add this line of code in UpdateTask activity.

this.Update_Task_TaskProperties = new SPWorkflowTaskProperties();
Update_Task_TaskProperties.ExtendedProperties[“ows_Comments”] = scpoShoppingCartNo;

This will assign the Comments entered by the approver to the Secondary Data Source we added in Step 1, that has been set the Default value for Comments field(Step 2). Now open the form to see the saved value .


Upgrading workflow in sharepoint

I had a problem with upgrading a workflow in sharepoint having the old workflow instances working on the existing items and the new instance applicable only to the items added hence. I also had to make few changes to the infopath form to have the new form functional.

Challenge :
The challenge here was to make the new changes working [ new infopath form and new workflow assembly] having the old workflow assembly and items still working. Installing new workflow assembly would overwrite the existing one . Hence wasn’t a feasible solution.

Resolution :
1. Deploy the new form[infopath] as a content type.
2.Upgrade the logic/code in workflow as needed ,create a new version of this workflow & deploy the assembly to GAC.
3.Set the exisiting workflow to “No new instances” .
4. Attach the modified workflow to the content type [ new infopath form deployed in step 1].

In Detail :
1. Deploy the infopath form as a content type
Deploying the browser form as a content type helps us to reuse forms across site collection and also attach workflows to the content types.
Read this for versioning in infopath.
2. Upgrade workflow , create new version and deploy the assembly to GAC.
Best way of doing this is to change the workflow.xml file so that the new workflow will have a different GUID & update the assembly version . Upgrading the exisiting assembly will break the exisiting instances . Since there is no versioning concept in features, deploy this solution as a new feature .
3.Set workflow for “No New Instances”
Go to Workflow setting > Remove workflow and check “No New Instances” againsts the existing workflow . This will make sure that new items will not be effected with the old workflow instance and will be associated only with the exisiting items in a list/library.
4. Attach workflow to content type
Associate the new workflow [deployed as a feature] with the upgraged form that is deployed in step 1.
To do this go to
Site settings
> Site Content type
> Click on content type to which thw workflow has to be attached.
> Workflow setting , associate workflow here .

Once we have this set up ready it can be noticied that while the old instances still keep working , the new one is applicable only to the items added to the library here after.