SharePoint Blogs / SharePoint University
SharePoint Blogs and SharePoint University - all in one place!
Need SharePoint Training? Attend a SharePoint Bootcamp!

Please delete cookies related to sharepointblogs.com and sharepointu.com to resolve login issues!

Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation

One of our customers wanted to use the out-of-the-box Approval workflow but wanted to pre-fill the Approvers field with users from the items metadata.  In another words, each document in a document library can potentially have a difference approver so rather than have the Approvers field pre-filled from the initial Association data, they want it populated from the Approvers field on the initiated item.

Initially, I started out modifying the out-of-the-box Approval InfoPath form (Review-RoutingInit.xsn) and was able to successfully populate the Approvers field with hardcoded data but I then realized that I didn’t know what Item the workflow had been started on, which meant I couldn’t figure out who the Approver was for the specific item that the workflow had been started.  So, I scrapped that idea and decided to create a new InfoPath Workflow initiation page (this is the page that loads the InfoPath Forms on initiation).

After using Lutz Roeder’s . NET Reflector to analyze the IniWrkflIPPage.aspx page, I was able to determine that if I wanted to change the AssociationData before it was populated into the InfoPath Form Control, I needed to modify the property m_formData before the page finished its databinding.

protected override void OnLoad(EventArgs ea)
{  
    base.OnLoad(ea);
  
   
/* Some code commented out */  
   
this.m_assocTemplate = SPWorkflowAssociationCollection.GetAssociationForListItemById(this.m_listItem, associationId);
  
   
this.m_formData = this.m_assocTemplate.AssociationData;  
--> this.m_formData = “My modified form data”;   
   
/* More code commented out */
  
   
this.DataBind(true);
}


I then went on to modify the form data using metadata from the item that initiated the workflow.  Because I wanted to inherit my custom InfoPath initiation form from IniWrkflIPPage.aspx, I realized that I couldn’t change the code in the OnLoad event, but instead needed to change it on the DataBind event. 

protected override void DataBind(bool raiseOnDataBinding)
{   
   if (m_listItem["Approver"] != null)
   
  
{
        
      
// Load form data into an XmlDocument
        
      
XmlDocument xmlDoc = new XmlDocument();
         
       
xmlDoc.LoadXml(this.m_formData);
         
       // Defines the namespace manager to handle using the 'my' namespace
        
      
XmlNamespaceManager manager = new XmlNamespaceManager(xmlDoc.NameTable);
        
      
manager.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD");
         
      
// Gets a collection of all the Users specificed in the Approver field (Requires Approver field on document library)
        
      
SPFieldUserValueCollection users = new SPFieldUserValueCollection(m_listItem.Web, m_listItem["Approver"].ToString());
        
      
string personXml = string.Empty;
         
      
// Loops through each user and builds out a new Person element
         
      
foreach (SPFieldUserValue user in users)
        
      
{
             
         
personXml += "<my:Person><my:DisplayName>" + user.User.Name + "</my:DisplayName><my:AccountId>" + user.User.LoginName + "</my:AccountId><my:AccountType>User</my:AccountType></my:Person>";
         
       
}
      // Selects the Reviewers (aka Approver) in the form data and sets the innerXml = to the collection of users we built        
     
xmlDoc.SelectSingleNode("/my:myFields/my:Reviewers", manager).InnerXml = personXml;
          // overwrites the default association data with our newly modified data
         this.m_formData = xmlDoc.InnerXml;  
}
}

As it turned out, apparently some of the global variables in the IniWrkflIPPage.aspx don’t “port” very well over to my custom page, so I ended up faking it a bit.  There is probably a better way to do this but at this point I didn’t care J

using System;
using System.Collections.Generic;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.Office.InfoPath.Server.Controls; 

namespace TeamEli.Sharepoint.Workflow.ApprovalWorkflow
{
  [PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust"), PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
  public class ApprovalIniWrkflIP : Microsoft.Office.Workflow.IniWrkflIPPage
  {
        //// Fields
        protected new string m_listItemName;
        protected new string m_listItemUrl;
        protected new string m_workflowName;
        protected new XmlFormView XmlFormControl;
         //// Methods
        protected override void OnInit(EventArgs e)
        {
            base.XmlFormControl = this.XmlFormControl;
            base.m_workflowName = this.m_workflowName;
            base.m_listItemName = this.m_listItemName;
            base.m_listItemUrl = this.m_listItemUrl;
            base.OnInit(e);
        }
         protected override void OnLoad(EventArgs ea)
        {
            base.OnLoad(ea);
            this.XmlFormControl = base.XmlFormControl;
            this.m_listItemName = base.m_listItemName;
            this.m_workflowName = base.m_workflowName;
        }

         protected override void DataBind(bool raiseOnDataBinding)        {            //// See above…        }
  }
}

With the code above precompiled into a DLL, all I needed to was modify two lines of my copied IniWrkflIPPage.aspx and that was to add my assembly and to change the page inherits to our new codebehind page.

<%@ Assembly Name="TeamEli.Sharepoint.Workflow.ApprovalWorkflow, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<<PUBLICKEYTOKEN>>"%>
<%@ Page Language="C#" Inherits="TeamEli.Sharepoint.Workflow.ApprovalWorkflow.ApprovalIniWrkflIP" MasterPageFile="~/_layouts/application.master"   EnableSessionState="true" AutoEventWireup="false"  %>

All that was left was to create a new Feature that calls our new initiation page.  And volia!

Hopefully some of this made sense.  If not, let me know.

Eli


Posted 06-20-2007 8:58 PM by undercoverlaptop

Comments

Sharepoint link love 06-21-2007 at Virtual Generations wrote Sharepoint link love 06-21-2007 at Virtual Generations
on 06-21-2007 3:32 AM

Pingback from  Sharepoint link love 06-21-2007 at  Virtual Generations

Mike Walsh's WSS and more wrote WSS FAQ additions and changes LX - 18th - 24th June 2007
on 06-24-2007 3:14 AM
Henry wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 07-09-2007 1:27 PM

I can't even find or activate the "out of the box approval workflow" it doesn't exist on my damn system.  so sick of this junk that doesn't work and documentation that doesn't match the crap they put out.

undercoverlaptop wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 07-10-2007 11:46 AM

Henry,

Sounds like you need to sit back and take a deep breath.  :)  Anyways, can you explain what you are trying to do so that I can help you out?

Thanks, Eli

vuong wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 08-02-2007 6:02 PM

Eli,

Could you please tell me where can I find the out-of-the-box Approval InfoPath forms??

undercoverlaptop wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 08-03-2007 10:32 PM

vuong,

Some of the Infopath formsare actually located in the Feature folder called ReviewWorkflows and then in the Forms folder.  Here is location on my machine...

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\ReviewWorkflows\Forms

Hope this is what you are looking for and that I am not too late ;)

Eli

nw wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 08-22-2007 4:02 PM

Eli-

Thanks for shedding some light on these mysterious "out of the box" aspx forms that come with MOSS! I was beginning to think it was a forbidden subject, because no-one to date seems to have said much about them.

I am building a custom ASSOCIATION form for a workflow created in WSS 3.0 (no MOSS) with Visual Studio 2005. My workflow forms were created with InfoPath 2007, are compiled into my workflow and have been published to Office Forms Server 2007.

I've modified workflow.xml file to use my custom aspx pages, have the InfoPath forms hosted in an XmlFormView control and everything deployed, but when I try to associate a workflow with my libraries I get an "unknown error" from SharePoint. I'm thinking either it's a syntax issue or I'm missing some code in my pages.

So my question: Do you know if anyone has run the Reflector and documented what these pages are supposed to contain?  That would be helpful for those of us who are doing this from scratch and don't have the MOSS pages as a starting point.

Thanks in advance

nw wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 08-29-2007 10:24 AM

I just found the reflector on Lutz's website and installed it - wow! what a handy tool!

My question is this: How did you use it to analyze aspx pages? Are these pages compiled into a dll somewhere?

Tx

undercoverlaptop wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 08-29-2007 12:36 PM

The best way to do this is to search for the “inherits” attribute within the aspx page.  You can find this attribute within the “Page” tag near the top of the aspx page.  

It looks something like this.

<%@ Page Language="C#" Inherits="Microsoft.SharePoint.ApplicationPages.SettingsPage" MasterPageFile="~/_layouts/application.master"   EnableViewState="false" EnableViewStateMac="false"   %>

The “inherits” attribute will tell you the namespace and class that this application (aspx) page uses.  Once you have this, you can defer what the dll is being used.  In the example above, it is Microsoft.SharePoint.ApplicationPages.  Therefore, you can open the Microsoft.SharePoint.ApplicationPages dll with Reflector and then navigate until you find a class that matches the inherits tag, in our example, SettingsPage.

HTH.

Eli

Sonu wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 10-12-2007 3:25 AM

Hi Eli,

I am not able to understand where can i find the onload and DataBind methods.

Frankly speaking, i am not able to get how to follow the specified process.

Can you please explain more details?

Thanks,

Sonu

Help wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 10-25-2007 9:05 AM

Is there any way to customize the Out of Box workflow where we can check if the modifier is same as approver? If they are then the workflow gives error that modifier cannot be same as Approver.

Thanks,

Sonu wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 10-26-2007 12:10 AM

It is such a nice article and i can able to fill the initiation form at run time.

But i have one query...

Can we prepopulate Association form at run time.

In my case, i'll be having a workflow which will be configured in two sites. In the approver field i am filling up the name of a site group, which is different in both the sites.

Is there any way to prefill the approvers field in association form with the group name depending on the site.

Sonu

Vimal wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 11-21-2007 7:41 AM

Hi, Good Works!!!

I implemeted the above in my portal. In my case, i am using the existing sharepoint approval. So i am retrieving the workflow's association data, modifying the approvers and starting the workflow during the check-in. During the checkin it goes to the workflow page, but none of my approver names were displayed it was blank. but if you see the list item, workflow was initiated and approver name also present there... I dont know how to resolve this problem as well as while starting a workflow i am receiving this exeception: Exception from HRESULT: 0x8102009B ---> System.Runtime.InteropServices.COMException (0x8102009B): Exception from HRESULT: 0x8102009B

Any words will be really helpful!!!

undercoverlaptop wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 11-21-2007 8:10 PM

Hi Vimal,

Can you email me a sample of your code, what you changed against what I posted?  I can take a look to see if anything stands out.

powerlaptop2001 at yahoo dot com

Take out _ in the above address ;)

Lutz Heil wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 01-14-2008 9:56 AM

Exception from HRESULT: 0x8102009B ---> System.Runtime.InteropServices.COMException (0x8102009B): Exception from HRESULT: 0x8102009B

I get this error when i assign the data to a running already running. Cancel the workflow and try again.

Hope it helps

Lui

Mark G wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 01-17-2008 12:14 PM

Hello, I am new to Sharepoint Design, but have developed part-time before.  I am attempting to add some fields to the canned "Helpdesk.wsp" workflow process, which other than a couple of missing fields, I am very happy with it.  First, I am having trouble finding the workflows I wish to modify.   Second, once located, I need to know the simplest way to add the fields we desire.  Third, I need to save and publish without losing the original flow as designed, in case we need to move forward with that instead.  Thanks!

Robert A. wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 05-15-2008 10:24 PM

Just a note, you can just copy the .aspx  and copy your "DataBind()" method into a "server-side" script.  

You don't even need to change the inheritance.

That way you just have the .aspx to deploy and your make sure your [workflow.xml] the [InstantiationUrl] to point to your new page.

Sagadudu wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 07-02-2008 12:02 PM

Hey Eli,

Wondeful post! I have a question that relates to what you did above: Is it possible to use the Reflector to mimic the Approval workflow and customize the approval buttons from; Approve, Reject, Cancel to Yes, No, True, False, and several other predefined buttons that all set to complete the workflow on click.

Sagadudu wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 07-02-2008 12:02 PM

Hey Eli,

Wondeful post! I have a question that relates to what you did above: Is it possible to use the Reflector to mimic the Approval workflow and customize the approval buttons from; Approve, Reject, Cancel to Yes, No, True, False, and several other predefined buttons that all set to complete the workflow on click.

nadia wrote re: Modifying the Workflow Association Data in SharePoint 2007 Pre-Initiation
on 01-07-2009 6:35 AM

I want to use the built in association form with document approval workflow in sharepoint with my custom workflow. how can i do this? i have to design the association form same like sharepoint and code it or i can use that built in associatioin form by any other way, i am sturuggling with this porblem from last 6 days. thanx in advance please help me

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Need SharePoint Training? Attend a SharePoint Bootcamp!
Posts (c) their respective authors. Everything else (c) 2009 SharePoint Experts, Inc.