I am trying to change fields of components without opening them in ComponentView. I have been testing following snippet but I get a strange error.


contentDocument_ = $j.parseXML(activity_.getContent())
activityTemplateFields_ = $xml.selectNodes(contentDocument_, "//*[local-name()='activity_template_fields']")[0]
activity_.setContent((new XMLSerializer()).serializeToString(contentDocument_),contentDocument_)

Error (The error message part):

The element 'Content' in namespace 'uuid:37f40dd9-afe8-40f2-b045-c653e5d68586' has invalid child 
element 'canceled' in namespace 'http:\/\/www.w3.org\/1999\/xhtml'. List of possible elements 
expected: 'training_certificate, url, canceled, full, location' in namespace 'uuid:37f40dd9-afe8-40f2-b045-c653e5d68586'.

When I end the snipper with .save(true) instead of .save(false) He tells me that item 'tcm:7-157-16_v0' does not exist (tcm:7-157-16 is correct btw).

Is there a solution to this error? Or maybe another way of changing/adding content to a component without opening it?

  • Where exactly is this code used, in a UI extension on the Item view? In that case the item is checked out for you already, and you should not call save(true), since the checkin will need to be done when the window is closed. Oct 14 '14 at 11:01
  • This is done in DashboardView using a GUI extension and the Component was not checked out. Oct 14 '14 at 11:46
  • That might explain the error, in your snipped you never checked out the Component, you can't save/check it in then either... Oct 14 '14 at 11:48
  • I just tried it with activity_.checkOut() activity_.save(false) activity_.checkIn() but I get the same error (I even tried with other fields) Oct 14 '14 at 11:56
  • Then my guess is that the Component isn't even fully loaded yet, keep in mind the UI is async. See tridion.stackexchange.com/questions/2695/… for details on loading an item. Oct 14 '14 at 12:21

The error you put in the question usually indicates that you try to insert a field in the component that either isn't defined in the schema, or that the inserted field is placed in the wrong order. I see the field 'canceled' is defined as the third field in the schema (see the 'expected' list).

To debug this, it would be best to check the xml you try to save from your gui extension, and compare it with the xml of an existing component.

I'm not sure about the error you get with the 'item does not exist'. Possibly, this is related to checking an item in or out - do you check out the item before you try to edit it via your GUI extension ?

  • 1
    An error stating that a -v0 version does not exists has something to do with either the item being checked out or locked. Since -v0 is added to a URI to reference the checked out version of that item. Oct 14 '14 at 10:59
  • @Harald Hoffelinck The canceled element is indeed a part of the schema and is at the correct spot. The 'url' element is not mandatory and was not filled in for that component. Oct 14 '14 at 11:41
  • could you try adding an empty <url> node before your <canceled> node Oct 14 '14 at 12:02
  • I also just noticed in your error message that your 'canceled' node has a namespace http:\/\/www.w3.org\/1999\/xhtml' That could also be the cause of your error. I do see you are trying to remove the xmlns from the node, but maybe that didn't work as expected. Could you try to output/debug the xml that gets serialized in (new XMLSerializer()).serializeToString(contentDocument_) ? Oct 14 '14 at 12:05
  • could you try with this code $j("<canceled xmlns=\"uuid:37f40dd9-afe8-40f2-b045-c653e5d68586\">yes</canceled>").insertAfter(activityTemplateFields_) and remove the next line ? Oct 14 '14 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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