+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Updating metadata from global.asax

Updating metadata from global.asax

9 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    09 Jan 2011
    Link to this post
    Hi,

    I am trying to set the content of a metafield from within the global.asax file by subscribing to the Telerik.Cms.Engine.ContentManager.Executed method, however I am getting the error message "Nolics.ORMapper.Base.NolnetException: The object belongs already into a different transaction"

    My code is:

        void ContentManager_Executed(object sender, Telerik.ExecutedEventArgs e) {
     
            //check what operation the user is carrying out
            switch (e.CommandName) {
     
                case "UpdateContent":
     
                    //get the provider
                    var providerName = (e.Data as Telerik.Cms.Engine.Data.CmsContentBase).ProviderName;
                     
     
                    switch (providerName) {
     
                        case "membersModule":
     
                            break;
     
                        case "publicationsModule":
     
                            IContent oContentItem = e.Data as IContent;
                            oContentItem.SetMetaData("ContactCounty", "Suffolk");
     
                            break;
     
    }
     
    }

    Essentially I want to update a field, just before the content item is published. Is this possible?

    Thanks
    higgsy
  2. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    09 Jan 2011
    Link to this post
    I looked at a different way of doing this and subscribed to the command of the workflowmenu button. I can update a metafield at the "Approve" stage, but not at the "Publish" stage - essentially SiteFinity goes off and approves the content before my own code runs.

    ALL i am trying to do is to update a metafield, just before the content is published. I am having to do this to get round an issue where I can't use the OR operator in search results because the OR operator is missing from the SiteFinity data layer - so this is the last and only option!

    Thanks
    higgsy
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Jan 2011
    Link to this post
    Hello higgsy,

    ContentManager_Executed is not called when you use Workflow. You can use LINQ to make OR filtering.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    10 Jan 2011
    Link to this post
    Hi Ivan, Thanks for your response, but I don't understand it. You say content_manager is not executed when using workflow, but my code definitely executes every time I publish. Where are you suggesting I use Linq or a filter? I can't use a filter because I need to use the OR operator, which doesn't exist. To get round this I decided to use a flag on a metafield, which is why I need to update that flag just before a content item is published. Can this be done? Thanks Higgsy
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Jan 2011
    Link to this post
    Hello higgsy,

    ContentManager_Executed is not called in the workflow steps. You cannot detect on which stage you are with ContentManager_Executed. You can use LINQ with standard operands like "||", "&&" etc. To make changes just before the item is published you can use the "Executing" event instead of "Executed"


    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    10 Jan 2011
    Link to this post
    Hi Ivan, Ok I'm going to try the executing method, a couple of quick questions before I do so. Is the content item passed into the executing method? If I attempt to update that content item and save it will I not get the same transactional nolics error? Thanks Higgsy
  7. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    10 Jan 2011
    Link to this post
    Ivan,

    I'm trying to update the metafield from within the contentmanager_executing method as suggested, like so:

    void ContentManager_Executing(object sender, Telerik.ExecutingEventArgs e) {
         
        //check what operation the user is carrying out
        switch (e.CommandName) {
     
            case "UpdateContent":
     
                IContent oContentItem = e.CommandArguments as IContent;
                 
                ContentManager op = new ContentManager("publicationsModule");
     
                StagedContent content = op.GetCurrentState(oContentItem.ID);
                content.SetMetaData("ContactCounty", "Denbigshire");
                op.SaveContent(content, ContentStatus.Draft);
     
                Workflow.ExecuteActivity(content.WorkflowInstanceId, "SendForApproval");
                Nolics.ORMapper.Base.DataConnection.InitWebRequest();
     
                Workflow.ExecuteActivity(content.WorkflowInstanceId, "Approve");
                Nolics.ORMapper.Base.DataConnection.InitWebRequest();
     
                break;
     
        }
         
    }

    However, I'm getting the error message:

    Only new or loaded objects can be joined into a transaction.

    Could you advise please?

    Thanks
    higgsy
  8. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    10 Jan 2011
    Link to this post
    Hi Ivan,

    Any further thoughts on this issue? I need to look at a different solution if it is not possible to update the content item from within the CMS_Executing method. This is literally the last bug I have to get round to get the website out for testing.

    Thanks
    higgsy
  9. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    13 Jan 2011
    Link to this post
    Hello higgsy,

    Could it be the workflow instance that is in different transaction? Please try with the approach taken in this forum post:
    http://www.sitefinity.com/devnet/forums/sitefinity-3-x/developing-with-sitefinity/auto-publish-page-when-approved-workflow-enabled.aspx

    All the best,
    Georgi
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
9 posts, 0 answered