ItemUpdating をオーバーライドするイベント レシーバーを持つカスタム リスト定義があります。このリストでは、メジャー バージョンとマイナー バージョンの作成とともに、コンテンツの承認がオンになっています。
アイテムが承認されている場合、バージョンと承認ステータスに影響を与えずに、ブール フィールド (Is Published?) を設定したいと考えています。SystemUpdate(false)がこれを行うと想定されていることは理解していますが、ブール値は保持されません。Update()またはSystemUpdate()を使用すると、値は保持されますが、承認ステータスが承認済みに設定されず、次のエラーがスローされます。
ファイル [ファイル名] は [日付] に [ユーザー] によって変更されました。
public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
EventFiringEnabled = false;
try
{
if (IsChangingToApproved(properties))
{
if (!Validate(properties))
{// This person can't approve
properties.ErrorMessage = "You don't have appropriate permissions.";
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.Cancel = true;
}
else
{// Set the IsPublished flag to true
var isPublishedField = properties.List.Fields["Is Published?"];
if (isPublishedField != null)
{
properties.ListItem[isPublishedField.InternalName] = true;
// Doesn't update bool, ItemUpdating event functions normally
properties.ListItem.SystemUpdate(false);
// Updates bool, but ItemUpdating event does not complete
//properties.ListItem.Update();
//properties.ListItem.SystemUpdate();
}
}
}
}
catch (Exception ex) { return; }
finally { EventFiringEnabled = true; }
}
私が試したこと:
using Site/using Web
プロパティから項目を更新する代わりに、ブロックで listItem を更新します。- properties.AfterProperties["Is Published?"] フィールドの設定。