Hello Team,
I am using <FS_CATALOG> where i am adding some names in it. After adding it it will be shown in the Site Store Variable.
After deleting all the "names" in the <FS_CATALOG> and clicking the ok button will remove the entries and remove the ss variable too.
After clicking the refresh button and opening my Script in context menu it opens the popup of <FS_CATALOG>, here still old values are shoes in the GUI screen.
How to delete the values or how to get which values are deleted in the screen??
Attached image for your reference,
I have listed the complete code for reference,
final PageRefFolder folder = (PageRefFolder) context.getElement();
boolean previousValues = false;
try {
if (!folder.getFormData().get(null, "ss_prep_area_users").isEmpty()) {
previousValues = true;
String users = folder.getFormData().get(null, "ss_prep_area_users").get();
Script script = context.getScript();
FormData defaultFormData = script.getFormDefaults();
Catalog cards = (Catalog) defaultFormData.get(null, "sc_user_list").get();
cards.clear();
SectionTemplate entry = context.getProject().getUserService().getTemplateStore().getSectionTemplates().getTemplate("prep_area_creator_input");
FormData entryFormData = context.requireSpecialist(FormsAgent.TYPE).getForm(entry.getGomSource()).createFormData();
for (String user : users.split(";")) {
entryFormData.get(null, "st_list_entry").set(user.trim());
Catalog.Card card = cards.create(entry, entryFormData);
cards.add(card);
}
defaultFormData.get(null, "sc_user_list").set(cards);
script.setFormDefaults(defaultFormData);
// entryFormData.get(null, "st_list_entry").set("");
}
} catch (Exception e) {
// looks like there is no old value
}
final FormData formData = context.showForm(false, "test_prep_area");
Catalog cards = (Catalog) formData.get(context.getProject().getMasterLanguage(), "sc_user_list").get();
StringBuilder sb = new StringBuilder();
for (Catalog.Card card : cards) {
Object userId = card.getItem().get(null, "st_list_entry").get();
if (userId != null) {
sb.append(userId.toString()).append(";");
}
}
try {
folder.setLock(true, false);
SiteStoreVariableFormData siteStoreFormData = folder.getFormData();
context.logInfo("sb:"+sb.toString());
context.logInfo("sb:"+sb.length());
if (sb.length() > 1) {
siteStoreFormData.createVariable(null, "ss_prep_area_users");
for (Language language : context.getProject().getLanguages()) {
FormField formField = siteStoreFormData.get(language, "ss_prep_area_users");
formField.set(sb.substring(0, sb.length() - 1));
folder.setFormData(siteStoreFormData);
}
folder.save();
folder.release(false);
requestOperation.setKind(RequestOperation.Kind.INFO);
requestOperation.setTitle("Success");
requestOperation.perform("User successfully added.");
} else if (previousValues) {
siteStoreFormData.removeVariable("ss_prep_area_users");
folder.setFormData(siteStoreFormData);
folder.save();
folder.release(false);
requestOperation.setKind(RequestOperation.Kind.INFO);
requestOperation.setTitle("Success");
requestOperation.perform("User successfully removed.");
}
} catch (Exception e) {
context.logError("Unknown error", e);
requestOperation.setTitle("Unknown error!");
requestOperation.perform("An error occurred: " + e);
} finally {
try {
folder.setLock(false, false);
} catch (Exception e) {
context.logError("Unknown error", e);
requestOperation.setTitle("Unknown error!");
requestOperation.perform("An error occurred: " + e);
}
}
Thank you,
Regards,
Siva