I was trying to create dynamic destination rule from a sharepoint web part. But I could not get any result. Here is my code.
protected void btnSubmit_Click(object sender, EventArgs e)
{
SourceCode.Workflow.Client.Connection conn = null;
try
{
conn = new SourceCode.Workflow.Client.Connection();
conn.Open("DLX");
SourceCode.Workflow.Client.ProcessInstance pi = conn.CreateProcessInstance("SampleApprovalSampleApprovalProcess");
strUsers = ppApprovers.CommaSeparatedAccounts.ToString();
string AllUsers = string.Empty;
string[] split = strUsers.Split(',');
foreach (string item in split)
{
AllUsers += item.Replace(@"", @""") + ",";
}
AllUsers = AllUsers.Remove(AllUsers.Length - 1, 1);
pi.XmlFields["subject"].Value = txtTitle.Text;
pi.XmlFields["message"].Value = txtDescription.Text;
//Response.Write(strUsers);
AssignReviewers(pi, AllUsers);
conn.StartProcessInstance(pi);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protected void AssignReviewers(ProcessInstance pins, string listOfUsers)
{
try
{
XmlDocument doc = new XmlDocument();
XmlElement root = null;
XmlNode userNode = null;
root = doc.CreateElement("UserList");
doc.AppendChild(root);
foreach (string user in listOfUsers.Split(','))
{
userNode = doc.CreateElement("Users");
userNode.InnerText = user;
root.AppendChild(userNode);
}
// Response.Write(doc.OuterXml.ToString());
//item.ProcessInstance.XmlFields[0].Value = doc.OuterXml;
pins.XmlFields["approvers"].Value = doc.OuterXml;
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
Please help me if you can.