Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Start site workflow with credentials of the logged in user

$
0
0

Hi,

We are using Sharepoint 2010 and Nintex 2010. We have a requirement to start a site workflow (Nintex) from a webpart. I have used runwithelevatedprivileges to start the workflow since the users may not have sufficient rights to start the workflow. I don't have any issues starting the workflow, but once the workflow starts when I check the workflow history, I see "started by" field set to "System Account" as a result of using "RunWithElevatedPrivileges". But this is an issue since it gives inaccurate info and also it's hard to track the workflow history.

My question is how to use the "RunWithElevatedPrivileges" (or something similar) and still retain the logged in user's identity so the "started by" field is set to the correct user. 

Any help is greatly appreciated.

My code snippet to start workflow is below:

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite elevatedSite = new SPSite(SPContext.Current.Site.ID))
                {
                    using (SPWeb elevatedWeb = elevatedSite.OpenWeb(SPContext.Current.Web.ID))
                    {
                        try
                        {
                            elevatedWeb.AllowUnsafeUpdates = true;
                            SPWorkflowAssociation wfAssoc = elevatedWeb.WorkflowAssociations.GetAssociationByName("SiteApprovalWorkFlow", CultureInfo.InvariantCulture);

                            if (wfAssoc != null && strOrderId != null)
                            {
                                SPWorkflow siteWF = elevatedSite.WorkflowManager.StartWorkflow(elevatedSite,
                                                                                       wfAssoc,
                                                                                       "<Data>AssociationData</Data>",
                                                                                       SPWorkflowRunOptions.Synchronous);
                            }
                            elevatedWeb.AllowUnsafeUpdates = false;
                        }
                        catch (Exception ex)
                        {
                            lblMessage.Visible = true;
                            lblMessage.Text = ex.Message;
                        }
                    }
                } 
             });

 


Viewing all articles
Browse latest Browse all 11571

Trending Articles