Good morning,
FirstSpirit 5.1.605.
I am writing a script to copy and update some pages. As part of the script, I need to add a Section which contains an FS_LIST. The list contains links. This is entirely scripted with no user intervention.
I don't understand the ValidationError I receive when the script tries to save the new page:
ValidationError[element='Previous_guidance' (ID=547055, project=466725), msg={MultiFormValidationReport{(EN:{st_related_content_links:[Validation{SAVE,false:Text},Validation{SAVE,false:Title},Valida...}]
It doesn't help that the error message is truncated!
Here is the script I am using:
Body relatedContent = page.getBodyByName("pt_related_topics_list");
if(relatedContent.getChildCount() == 0) {
SectionTemplate st_related_content = templateStore.getStoreElement("st_related_content",IDProvider.UidType.TEMPLATESTORE);
Section guidanceSection = relatedContent.createSection("Previous_guidance",st_related_content);
guidanceSection.setLock(true,false);
FormData rcFormData = guidanceSection.getFormData();
FormField linksField = rcFormData.get(lang,"st_related_content_links");
FormDataList dataList = linksField.get();
producer = dataList.getProducer();
lt_internal_link = templateStore.getStoreElement("lt_internal_link",IDProvider.UidType.TEMPLATESTORE_LINKTEMPLATE);
formData = producer.create(lt_internal_link,lang);
linkT = formData.getTemplate();
link = linkT.createLink(lang);
linkFD = link.getFormData();
lt_link_type = linkFD.get(lang,"lt_link_type");
lt_link_type.set(true);
lt_title = linkFD.get(lang,"lt_title");
lt_title.set("Link Title Bananas");
lt_text = linkFD.get(lang,"lt_text");
lt_text.set("Link Text Fruit Salad");
lt_reference = linkFD.get(lang,"lt_reference");
// this is how you set an FS_REFERENCE value
originalRef = TargetReference.TargetReferences.newInstance(lang, original, null);
lt_reference.set(originalRef);
link.setFormData(linkFD);
// *** I think the error might be around here? Have I missed a step?
dataList.add(formData);
linksField.set(dataList);
guidanceSection.setFormData(rcFormData);
guidanceSection.save();
guidanceSection.setLock(false,false);
}
The link template requires lt_link_type (a CMS_INPUT_TOGGLE), lt_title and lt_text (both CMS_INPUT_TEXT) and lt_reference (an FS_REFERENCE) to be valid.
When I inspect the Section ("Previous_guidance") in SiteArchitect, the list is empty so I don't think I am saving the Section or Form correctly.
Can anyone see any obvious errors in my script? Or help me understand the ValidationError?
Many thanks,
Liam Davison