Updating multiple values in a lookup column in MOSS is bit hard due to some limitations in MOSS 2007.
Here is a simple method to update multi valued lookup column in MOSS 2007. So what should be appropriate technology?
All the MOSS (Microsoft Office Share Point) developers tend to use Microsoft Office Share Point Designer 2007 as simple development tool for workflow development, Web Parts etc… I’m going to integrate this tool with Visual Studio .NET 2008 and then update our multi valued lookup column using workflow.
First we create a workflow action and then the action is attached to our workflow through Microsoft Office Share Point Designer 2007.
Let’s create the workflow action
Lookup column is in Department List
Lookup column name = Members
Target List = Member List
sing System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Diagnostics;
using System.Linq;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;
using Microsoft.SharePoint.WorkflowActions;
namespace UpdateMultipleMembers
{
public partial class UpdateContacts: SequenceActivity
{
public UpdateMembers ()
{
InitializeComponent();
}
private EventLog _log;
We have to define three varables as follows. Code snippts in VS 2008 help us to create this varables.
public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(UpdateContacts));
[DescriptionAttribute("__Context")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public WorkflowContext __Context
{
get
{
return ((WorkflowContext)(base.GetValue(UpdateContacts.__ContextProperty)));
}
set
{
base.SetValue(UpdateContacts.__ContextProperty, value);
}
}
public static DependencyProperty ListIdProperty = DependencyProperty.Register("ListId", typeof(string), typeof(UpdateContacts));
[DescriptionAttribute("ListId")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public string ListId
{
get
{
return ((string)(base.GetValue(UpdateContacts.ListIdProperty)));
}
set
{
base.SetValue(UpdateContacts.ListIdProperty, value);
}
}
public static DependencyProperty ListItemProperty = DependencyProperty.Register("ListItem", typeof(int), typeof(UpdateContacts));
[DescriptionAttribute("ListItem")]
[BrowsableAttribute(true)]
[DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
public int ListItem
{
get
{
return ((int)(base.GetValue(UpdateContacts.ListItemProperty)));
}
set
{
base.SetValue(UpdateContacts.ListItemProperty, value);
}
}
Now we define the action inside “Execute” method.
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
_log = new EventLog("Multiple Members Workflow");
_log.Source = "Share Point Workflows";
try
{
SPSite _site = (SPSite)(__Context.Site);
SPWeb _web = (SPWeb)(__Context.Web);
SPList _list = _web.Lists[new Guid(this.ListId)];
SPListItem _listItem = _list.GetItemById(this.ListItem);
UpdateLastComdate(_web, _listItem);
}
catch (ExecutionEngineException ex)
{
_log.WriteEntry("Error" + ex.Message.ToString(), EventLogEntryType.Error);
}
return ActivityExecutionStatus.Closed;
}
Here we retrieve date values from Department list and update our lookup list (Members).
private void UpdateLastComdate(SPWeb _web, SPListItem _listItem)
{
string[] contacts = _listItem["Department"].ToString().Split('#', ';');
DateTime Date = Convert.ToDateTime(_listItem["Date"]);
int _length = contacts.Length;
string[] contactID = new string[_length / 2];
string[] contactName = new string[_length / 2];
int j = 0;
int k = 0;
for (int i = 0; i < mylist2 =" _web.Lists[" i =" 0;" id =" Convert.ToInt32(contactID[i]);" _listitem2 =" myList2.GetItemById(id);">”
Underneath this tag “authorizedtypes”
Add this tag
authorizedtype publickeytoken="public Key" culture="neutral," version="1.0.0.0," assembly="”UpdateMultipleMembers," namespace="”" typename="”*”" authorized="”True”"
3. Update .ACTION file
Open C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\Workflow folder
Open “WSS.ACTIONS” file in note pad
Append following code before /actions tag (Fill “<
Action Name=”Update Multiple Member Records”
ClassName=” UpdateMultipleMembers. UpdateMembers”
Assembly=” UpdateMultipleMembers, Version=1.0.0.0,
Culture=neutral, PublicKeyToken= add the key here”
AppliesTo=”all”
Category=”Extras”
ruledesigner sentence="”"
fieldbind id="”1”" designertype="”ChooseListItem”" text="”this" field="”ListId,ListItem”"
/ruledesigner
parameters
parameter direction="”In”" type="”Microsoft.SharePoint.WorkflowActions.WorkflowContext”" name="”__Context”"
parameter direction="”In”" type="”System.String," name="”ListId”"
parameter direction="”In”" type="”System.Int32," name="”ListItem”"
/parameters
/action
Now you can see this action in share point designer as a custom action and then create the workflow using our custom action “Update Multiple Member Records”.
Enjoy...