Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Damon 217 posts 287 karma points
    Feb 17, 2016 @ 15:03
    Damon
    0

    Programmatically updated a field in the backoffice

    Hi,

    I am capturing the save event using private void ContentService_Saving(IContentService sender, SaveEventArgs

    Now, using e.SavedEntities, I can then update a given field in the page being saved, using its alias, as shown below. But how do you update other pages, not just the one being saved at that time?

    Thanks a lot!

        private void ContentService_Saving(IContentService sender, SaveEventArgs<IContent> e)
        {   
    

    foreach(var item in e.SavedEntities) { item.Properties["fieldName"].Value = "test 2"; }

  • Lars-Erik Aabech 348 posts 1096 karma points MVP 4x c-trib
    Feb 17, 2016 @ 15:18
    Lars-Erik Aabech
    1

    You can fetch them with IContentService.GetByIds().
    For instance

    var otherId = Convert.ToInt32(item.Properties["relatedThing"].Value);
    var otherItem = sender.GetByIds(otherId);
    otherItem.Properties["someField"].Value = "Some value for the other thing";
    sender.Save(otherItem, raiseEvents:false); // false to avoid recursive Saving event
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies