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.
Snippet:
contentDocument_ = $j.parseXML(activity_.getContent())
activityTemplateFields_ = $xml.selectNodes(contentDocument_, "//*[local-name()='activity_template_fields']")[0]
$j("<canceled>yes</canceled>").insertAfter(activityTemplateFields_)
$xml.selectNodes(contentDocument_,"//*[local-name()='canceled']")[0].removeAttribute("xmlns")
activity_.setContent((new XMLSerializer()).serializeToString(contentDocument_),contentDocument_)
activity_.save(false)
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?
save(true)
, since the checkin will need to be done when the window is closed.