mir eine Workflow-Aufgabe der listItem in Sharepoint erschaffe 2013. Der Workflow funktioniert gut, wenn ich den Listeneintrag am Hinzufügen der Aufgabe erstellt wird, und es ist kein Fehler. Allerdings, wenn ich den Artikel am Aktualisierung der Workflow-Code gibt mir diese Fehlermeldung:<nativehr> 0x8102009b</nativehr><nativestack></ nativestack> Workflow Sharepoint 2013
<nativehr>0x8102009b</nativehr><nativestack></nativestack>
Stacktrace
at HBLEventReceiverWP.ApprovalWFRecevier.ApprovalWFRecevier.LookupAndStartWorkflow(SPListItem listItem, SPWorkflowManager manager, SPWorkflowAssociationCollection associationCollection, String workflowId)
at HBLEventReceiverWP.ApprovalWFRecevier.ApprovalWFRecevier.ItemUpdated(SPItemEventProperties properties)
at Microsoft.SharePoint.SPEventManager.RunItemEventReceiver(SPItemEventReceiver receiver, SPUserCodeInfo userCodeInfo, SPItemEventProperties properties, SPEventContext context, String receiverData)
at Microsoft.SharePoint.SPEventManager.RunItemEventReceiverHelper(Object receiver, SPUserCodeInfo userCodeInfo, Object properties, SPEventContext context, String receiverData)
at Microsoft.SharePoint.SPEventManager.<>c__DisplayClassa`1.<InvokeEventReceiver>b__7()
at Microsoft.SharePoint.SPSecurity.RunAsUser(SPUserToken userToken, Boolean bResetContext, WaitCallback code, Object param)
Dies ist mein Code auf itemupdated
Ereignis.
public class ApprovalWFRecevier : SPItemEventReceiver
{
/// <summary>
/// An item was updated.
/// </summary>
public override void ItemUpdated(SPItemEventProperties properties)
{
base.ItemUpdated(properties);
// get site collection web
using (SPWeb spWeb = properties.OpenWeb())
{
// get current site
SPSite spSite = spWeb.Site;
//
spWeb.AllowUnsafeUpdates = true;
// check if it is a component list
bool isCompLst = CheckIsComponentList(properties.List.ToString());
if (isCompLst == true)
{
// set the list item
SPListItem listItem = properties.ListItem;
// check if item is in preview mode
if (properties.List.ToString() == "SitePages")
{
if (Convert.ToBoolean(listItem["Preview"]) == false)
{
SPWorkflowManager manager = spSite.WorkflowManager;
//get item's parent list
SPList parentList = listItem.ParentList;
//get all workflows that are associated with the list
SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
//lookup and start the worflow
LookupAndStartWorkflow(listItem, manager, associationCollection, "Approval");
}
}
else if (CheckPreviewCol(listItem, properties) == false)
{
//obtain an instance of SPWorkflowManager
//which will be later used to start the workflow
SPWorkflowManager manager = spSite.WorkflowManager;
//get item's parent list
SPList parentList = listItem.ParentList;
//get all workflows that are associated with the list
SPWorkflowAssociationCollection associationCollection = parentList.WorkflowAssociations;
//lookup and start the worflow
LookupAndStartWorkflow(listItem, manager, associationCollection, "Approval");
}
}
}
}
#region Methods
public bool CheckIsComponentList(string listName)
{
try
{
bool IsCompLst = false;
switch (listName)
{
case "HeadingComponent":
// set component list to true
IsCompLst = true;
break;
case "ParagraphComponent":
// set component list to true
IsCompLst = true;
break;
case "FAQComponent":
// set component list to true
IsCompLst = true;
break;
case "FAQComponentDetail":
// set component list to true
IsCompLst = true;
break;
case "BulletComponent":
// set component list to true
IsCompLst = true;
break;
case "BulletComponentDetail":
// set component list to true
IsCompLst = true;
break;
case "ButtonsComponent":
// set component list to true
IsCompLst = true;
break;
case "TwoImageComponent":
// set component list to true
IsCompLst = true;
break;
case "ImageGridComponent":
// set component list to true
IsCompLst = true;
break;
case "ImageWithDescriptionComponent":
// set component list to true
IsCompLst = true;
break;
case "GreenTextComponent":
// set component list to true
IsCompLst = true;
break;
case "TableComponent":
// set component list to true
IsCompLst = true;
break;
case "TableComponentRows":
// set component list to true
IsCompLst = true;
break;
case "CenterComponent":
// set component list to true
IsCompLst = true;
break;
case "CenterComponentDetail":
// set component list to true
IsCompLst = true;
break;
case "SitePages":
// set component list to true
IsCompLst = true;
break;
default:
// set component list to true
IsCompLst = false;
break;
}
return IsCompLst;
}
catch (Exception ex)
{
throw ex;
}
}
public bool CheckPreviewCol(SPListItem listItem, SPItemEventProperties properties)
{
try
{
bool isPreview = true;
bool oldValue = listItem["Preview"] != null ? Convert.ToBoolean(listItem["Preview"]) : true;
if (oldValue == true)
{
bool newValue = properties.AfterProperties["Preview"] != null ? Convert.ToBoolean(properties.AfterProperties["Preview"]) : true;
if (oldValue != newValue)
isPreview = false;
}
else
isPreview = false;
return isPreview;
}
catch (Exception ex)
{
throw ex;
}
}
private static void LookupAndStartWorkflow(SPListItem listItem, SPWorkflowManager manager, SPWorkflowAssociationCollection associationCollection, string workflowId)
{
try
{
//iterate workflow associations and lookup the workflow to be started
foreach (SPWorkflowAssociation association in associationCollection)
{
//if the workflow association matches the workflow we are looking for,
//get its association data and start the workflow
if (association.Name.ToLower().Equals(workflowId.ToLower()))
{
//get workflow association data
string data = association.AssociationData;
//start workflow with privileges
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWorkflow wf = manager.StartWorkflow(listItem, association, data, true);
});
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}