Thursday, September 09, 2010

.NET forms integration within the Sharepoint workflow

Overview:

This article explains you how to get data into the Workflow from “Custom User Forms.” It turns out that SharePoint allows developers to prompt the administrators and users for information at several stages along the workflow:.

When is the workflow done connected to a SharePoint List or Document Library. This is by building and attaching aSharePoint Association Form which allows the Administrator, or a user, who connects the workflow to a SharePoint List, to set “default” values and behavior for the workflow.

Just workflow is before the prompt the user started, which gives the developer an opportunity to for information that might be needed at the start of the workflow and/or give the user an opportunity to override the default values defined via the Association Form. This is done by providing the user with a custom Instantiation/Initiation form

At running anytime during a workflow, by providing a Modification form

By assigning users Tasks (think” Outlook Tasks”), using Task-Edit forms

This workshop will focus on the Instantiation or Initiation form. The SharePoint documentation and API refers to this form by both names, but for this workshop I will refer to it as the Instantiation form. Here we are creating the initiation page

Here we are creating the custom ASPX form as the initiation page, when user invoke the instance of the workflow then first he will see that form. After submission of this form workflow will be triggered

1.How we can refer to the back end assembly/dll in the ASPX. Inherits from the NameSpace

+ BackEnd Code

<%@ Page Language="C#" EnableSessionState="True" EnableViewState="true" ValidateRequest="false" Inherits="AmitKumar.F.V.Workflows..

PublishToLibrary.Instantiation" %>

2. Where we create our design.

<asp:panel id="pnlContent" runat="server" visible="true">

<wssuc:InputFormSection Title="Product Line" Description="" runat="server">

<template_inputformcontrols>

<wssuc:InputFormControl runat="server" LabelText="" >

<Template_Control>

<%--This is your form area, here you can create your form design--%>

</div>

</Template_Control>

</wssuc:InputFormControl>

</template_inputformcontrols>

</wssuc:InputFormSection>

3. How we get the workflow properties in the ASPX form.

<input type="hidden" name="WorkflowDefinition" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["WorkflowDefinition"]),Response.Output); %>'/>

<input type="hidden" name="WorkflowName" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["WorkflowName"]),Response.Output); %>'/>

<input type="hidden" name="AddToStatusMenu" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["AddToStatusMenu"]),Response.Output); %>'/>

<input type="hidden" name="AllowManual" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["AllowManual"]),Response.Output); %>'/>

<input type="hidden" name="RoleSelect" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["RoleSelect"]),Response.Output); %>'/>

<input type="hidden" name="GuidAssoc" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["GuidAssoc"]),Response.Output); %>'/>

<input type="hidden" name="SetDefault" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["SetDefault"]),Response.Output); %>'/>

<input type="hidden" name="HistoryList" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["HistoryList"]),Response.Output); %>'/>

<input type="hidden" name="TaskList" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["TaskList"]),Response.Output); %>'/>

<input type="hidden" name="UpdateLists" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["UpdateLists"]),Response.Output); %>'/>

<input type="hidden" name="AutoStartCreate" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["AutoStartCreate"]),Response.Output); %>'/>

<input type="hidden" name="AutoStartChange" value='<% SPHttpUtility.NoEncode(SPHttpUtility.HtmlEncode(Request.Form["AutoStartChange"]),Response.Output); %>'/>

<SharePoint:FormDigest ID="FormDigest1" runat="server" />

4. Inherit class.

public class Instantiation : LayoutsPageBase

5. Set Master page at the run time.

protected override void OnPreInit(EventArgs e)

{

base.OnPreInit(e);

this.objWeb = SPContext.Current.Web;

// Set Master page at the run time

this.MasterPageFile = objWeb.MasterUrl;

}

6. Check context on page load.

if (base.Context != null)

{

if (SPControl.GetContextWeb(base.Context) != null)

{

}

}

7. Custom Submit button to invoke the workflow, and pass initiation data through serialization.

public void cmdSubmit_OnClick(object sender, EventArgs e)

{

string RedirectUrl = this.List.DefaultViewUrl;

SPLongOperation op = new SPLongOperation(this);

try

{

op.Begin();

try

{

this.objWeb.Site.WorkflowManager.StartWorkflow(this.ListItem, this.Association, this.InitiationDataToXml(), true);

}

catch (UnauthorizedAccessException ex)

{

SPUtility.HandleAccessDenied(ex);

}

catch (Exception ex)

{

SPUtility.TransferToErrorPage(ex.Message);

}

op.End(RedirectUrl, SPRedirectFlags.Static, this.Context, null);

}

finally

{

if (op != null)

op.Dispose();

}

}

8. Update workflow.xml file to invoke the initiation page.

<Workflow

Name="V Publish To Library"

Description="This workflow publishes the documents to the Varian ELibrary."

Id="0F5CE373-78A1-41DC-B70C-704497D51239"

CodeBesideClass="AmitKumar.F.V.Workflows.VPublishToLibrary.SubmitToLibrary"

CodeBesideAssembly="AmitKumar.F.V.VPublishToLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b0d0369bcaffb497"

InstantiationUrl="_layouts/AmitKumar/VWorkflows/Instantiation.aspx">

<Categories/>

</Workflow>


Share:

0 comments:

About Me

My photo
Based in Bangalore, INDIA, Amit is a MCC. He has an MCA from the U.P.T.U., INDIA and holds Microsoft certifications including SharePoint 2007/2010/2013. He is an contributor to MSDN and http://amitkumarmca04.blogspot.com/. Amit have experience in SharePoint,ASP.Net with C#, Classic ASP, VB,Macros,HTML,JavaScript,JSON,BootStrap and AngularJS.

Followers

Labels