1
が正常に動作します。しかし私は、ワークフローのコードは私にこのエラーを与えるアイテムを更新していたとき:<nativehr> 0x8102009b</nativehr><nativestack></ nativestack>ワークフロー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)
これはitemupdated
イベントに私のコードです。
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
}