How to get the context item in Workflow activity (SharePoint)

后端 未结 6 1761
萌比男神i
萌比男神i 2021-02-20 06:56

I am writing custom activity for sharepoint workflow and I don\'t know how I can use current workflow item, SPWeb or SPSite.

I see http://blogs.microsoft.co.il/blogs/dav

6条回答
  •  时光取名叫无心
    2021-02-20 07:53

    I try this code and runs as well bat the contex objet always is null. some one know why?

    protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
    
    
            //return base.Execute(executionContext);
            int IdRetorno = -1;
    
    
    
            try {
                SPSecurity.RunWithElevatedPrivileges(delegate
                {
                    LogExceptionToWorkflowHistory("Inicio:", executionContext, WorkflowInstanceId);
                    using (SPSite sitio = new SPSite(this.__Context.Site.ID))
                    {
    
                        using (SPWeb web = sitio.AllWebs[this.__Context.Site.ID])
                        {
    
    
                            SPList sourceList = web.Lists[new Guid(ListId)];
                            LogExceptionToWorkflowHistory(ListId, executionContext, WorkflowInstanceId);
                            SPList destinoList = web.Lists[new Guid(SourceListId)];
                            LogExceptionToWorkflowHistory(SourceListId, executionContext, WorkflowInstanceId);
                            SPListItem sourceItem = sourceList.Items.GetItemById(ListItem);
                            LogExceptionToWorkflowHistory(ListItem.ToString(), executionContext, WorkflowInstanceId);
    
                            SPListItem destinoItem = destinoList.Items.Add();
                            CopyFieldValues(sourceItem, destinoItem);
                            destinoItem.SystemUpdate();
    
                            sourceItem.Delete();
                            IdRetorno = destinoItem.ID;
                        }
                    }
    
                });
    
            }
            catch (Exception ex) {
                if (!System.Diagnostics.EventLog.SourceExists("MyApp1"))
                    System.Diagnostics.EventLog.CreateEventSource(
                       "MyApp1", "Application");
    
                EventLog EventLog1 = new EventLog();
                EventLog1.Source = "MyApp1";
                EventLog1.WriteEntry(ex.Message,EventLogEntryType.FailureAudit);
    
                LogExceptionToWorkflowHistory(ex.Message, executionContext, WorkflowInstanceId);
            }
    
    
            OutListItemID = IdRetorno;
    
    
    
    
            return base.Execute(executionContext);
    
        }
    

    thanks

提交回复
热议问题