0

I am working in Tridion event code 2011. I am trying to save the component by the below code, it is getting checkedout but not getting save

  try
                {
                    component.Save(true);
                }
                catch(TridionComException ex)
                {
                    EventHelper.WriteEventToHTMLLog("Tridion : Error -" + (!string.IsNullOrEmpty(ex.Message) ? ex.Message : "Null") + "-->StackTrace: " + (!string.IsNullOrEmpty(ex.StackTrace) ? ex.StackTrace : "Null"));
                }

Also , the exception is not caught in the main Exception class. I assume there is some problem in the component save. I updated the content of the component and i checked by below

component.Content.OuterXml

What can be the issue?

5
  • 1
    Are you calling Save() from the Event System? If you're modifying the component for which the event is triggered it's much easier to just use the Initialized phase of the event, and make your changes - no need to save them, Tridion will save your changes on the next phase of the Event.
    – Nuno Linhares
    Commented Mar 13, 2014 at 16:24
  • 2
    Without knowing in what event context you are calling component.Save() and how you obtained a reference to component you will only get guesses at an answer. Please edit your question and update it with more information, the fact that a TridionComException is not thrown means nothing here. Commented Mar 13, 2014 at 17:11
  • Good point Bart, hadn't even noticed the catch was on TridionComException - Tridion 2011 doesn't always use COM
    – Nuno Linhares
    Commented Mar 13, 2014 at 20:34
  • @Nuno- Yes i am calling the save from event system. But there is no triggering of the event when the component is saved. The component has a body field which contains xml nodes. The component is attached to a page of type .xml. So my aim is to modify the content of the component ,save it and publish the page which indirectly will produce a xml file which is required on our site for image gallery display.
    – Urvesh
    Commented Mar 14, 2014 at 11:18
  • You say the event is not fired: how are you attaching to the event? And is this .NET event system or still COM? Please add the info to your question for clarity.
    – Nuno Linhares
    Commented Mar 14, 2014 at 12:40

1 Answer 1

5

I can think of a couple of things that could be going wrong here. What is the context of the code you are running? It this the only save event you are subscribed to for this component? And what phase are you running in? I've ran into problems when trying to do a 'double' check-in etc. If you are running in the 'initiated' phase you do not need to perform the save, because the item is not saved to the database and will be saved and checked-in due to the nature of the phase. Perhaps you could add a bit more of the code so we could see what is going on.

With that being said, try the following code to check out a component, updating it's content and ensuring it is checked back in.

bool isCheckedOut = component.TryCheckOut();
if (isCheckedOut)
{
    // do something with the component
    component.Save(true); // enforcing the check-in like you've done.
}

The 'TryCheckOut()' will check the component out if it is not previously checked out, and also ensures that the checkout was successful. Are you sure this component is not shared (and is localized / the root component)? If none of the above helps you out, post a bit more of your code and the event subscriptions and I will try to help you out.

Have a look at the great article by Bart describing the event phases here.

2
  • I will try out your code, for the exception, i am getting none.. I will get back to you. Thanks
    – Urvesh
    Commented Mar 13, 2014 at 16:17
  • I have tried as per your suggestion but I got value of isCheckedOut as 'false', even though i have checked out the component by the code ' EventHelper.WriteEventToHTMLLog("S-CheckOut"); component.CheckOut(true); EventHelper.WriteEventToHTMLLog("E-CheckOut");' . I dont get any exception while doing checkout. What can be the reason that i get false?
    – Urvesh
    Commented Mar 14, 2014 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.