Running the Designer workflow by c# code
=========================================================
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite osite = new SPSite(SPContext.Current.Web.Url))
using (SPWeb oweb = osite.OpenWeb())
{
osite.AllowUnsafeUpdates = true;
SPList oListSecScore = oweb.Lists.TryGetList("Active Appraisals");
SPListItemCollection oListColl = oListSecScore.Items;
SPListItem oListItem = oListColl.Add();
oListItem["Title"] = "Appraisal_" + appraisalyr + "_" + ddlStaffId.SelectedValue;
oListItem["SubmitterCmnt1"] = txtSubmitterCmt.Text.Trim();
SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection();
SPFieldUserValue usertoadd = General.ConvertLoginAccount(pendinguser);
usercollection.Add(usertoadd);
oListItem["PendingUser"] = usercollection;
SPFieldUserValueCollection userstaff = new SPFieldUserValueCollection();
SPFieldUserValue useraddstaff = General.ConvertLoginAccount(ddlStaffId.SelectedValue);
userstaff.Add(useraddstaff);
oListItem["Staff"] = userstaff;
oListItem.Update();
SPWorkflowAssociationCollection associationCollection = oListSecScore.WorkflowAssociations;
foreach (SPWorkflowAssociation association in associationCollection)
{
if (association.Name == "PendingUserWF")
{
association.AutoStartChange = true;
association.AutoStartCreate = true;
association.AssociationData = String.Empty;
osite.WorkflowManager.StartWorkflow(oListItem, association, association.AssociationData);
}
}
osite.AllowUnsafeUpdates = false;
}
});
=========================================================
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPSite osite = new SPSite(SPContext.Current.Web.Url))
using (SPWeb oweb = osite.OpenWeb())
{
osite.AllowUnsafeUpdates = true;
SPList oListSecScore = oweb.Lists.TryGetList("Active Appraisals");
SPListItemCollection oListColl = oListSecScore.Items;
SPListItem oListItem = oListColl.Add();
oListItem["Title"] = "Appraisal_" + appraisalyr + "_" + ddlStaffId.SelectedValue;
oListItem["SubmitterCmnt1"] = txtSubmitterCmt.Text.Trim();
SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection();
SPFieldUserValue usertoadd = General.ConvertLoginAccount(pendinguser);
usercollection.Add(usertoadd);
oListItem["PendingUser"] = usercollection;
SPFieldUserValueCollection userstaff = new SPFieldUserValueCollection();
SPFieldUserValue useraddstaff = General.ConvertLoginAccount(ddlStaffId.SelectedValue);
userstaff.Add(useraddstaff);
oListItem["Staff"] = userstaff;
oListItem.Update();
SPWorkflowAssociationCollection associationCollection = oListSecScore.WorkflowAssociations;
foreach (SPWorkflowAssociation association in associationCollection)
{
if (association.Name == "PendingUserWF")
{
association.AutoStartChange = true;
association.AutoStartCreate = true;
association.AssociationData = String.Empty;
osite.WorkflowManager.StartWorkflow(oListItem, association, association.AssociationData);
}
}
osite.AllowUnsafeUpdates = false;
}
});
No comments:
Post a Comment