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 288 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 349 posts 1100 karma points MVP 8x 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
    
Please Sign in or register to post replies

Write your reply to:

Draft