2016-08-17 3 views
0

私はカスタムItemUpdatingイベントレシーバを登録するSharePointリストを持っていますが、このソリューションでは本当に奇妙な動作がいくつか見られます。この現象は、イベント受信側にbase.ItemUpdating以外のコードを追加した場合に発生します。奇妙なSharePoint ItemUpdating動作

イベントレシーバーをデバッグすると、properties.AfterPropertiesにはフィールドに入力されたすべての値があり、properties.ListItemには元のアイテムが含まれていることがわかります。しかし、ERが実行されてページがリロードされると、何も保存されず、値を変更する前の状態に戻ります。もっと奇妙なことに、私が行って手動で以下のようなプロパティを設定すると、動作し、アップデートが正しく保存されます。だから、基本的にイベントレシーバーはアイテムの変更を私に任せていますが、これはItemUpdatingの通常の動作ではありません。これを引き起こす原因は誰にも分かりますか?あなたがすべてで現在の項目を保存していないので、

public override void ItemUpdating(SPItemEventProperties properties) 
{ 
    var recurringBefore = properties.ListItem.TryGetValue<bool>(Constants.CommonFields.Recurring_STATIC); 
    var recurringAfter = Convert.ToBoolean(properties.AfterProperties[Constants.CommonFields.Recurring_STATIC]); 

    //This loop is the horrible fix I have done to manually update the relevant fields but this shouldn't be necessary 
    var item = properties.ListItem; 
    foreach (SPField key in item.Fields) 
    { 
     if (item[key.InternalName] != properties.AfterProperties[key.InternalName] && key.CanBeDisplayedInEditForm && properties.AfterProperties[key.InternalName] != null) 
     { 
      //looping through and setting the AfterProperties to what they already are makes them save? If I don't do this nothing saves 
      properties.AfterProperties[key.InternalName] = properties.AfterProperties[key.InternalName].ToString(); 
     } 
    } 

    if (!recurringBefore && recurringAfter && 
     currWfStatus == Constants.WorkflowStatus.Processed) 
    { 
     //do some stuff 
    } 
    base.ItemUpdating(properties); 
} 
+0

あなたは 'base.ItemUpdating(プロパティ)'あなたの関数のオーバーライドの先頭に代わりのを起動しようとしたことがあり最後に? – Thriggle

+0

ええ、違いはありません。 –

答えて

0

がそれです、このような何か:

item.update(); 
+0

いいえ、項目を保存する前に変更を行っているため、ItemUpdatingに更新は不要です。 –