how to retrieve the previously authored data if I have changed the component dialog box for component in AEM as a cloud service | Community
Skip to main content
Level 4
September 21, 2022
Solved

how to retrieve the previously authored data if I have changed the component dialog box for component in AEM as a cloud service

  • September 21, 2022
  • 3 replies
  • 1386 views

->I have a component where earlier there were three fields stored under the name : ./name , ./address , ./phonenum

->  I have changed the component dialog box and made those fields multifield

->but I want my previously authored data to be stored as the first entry of the multifield

-> for e.g : Now I have three items in my multifield  and I want the previously authored data to be populated in my first item in             multifield

-> this component is used in multiple pages I don't want to reauthor everything  , that's why I want the first multifield to be populated with the previously authored data (before enhancement).

 

Thank you

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by rahul234dabas

Doing this via groovy Script now ,

I am fetching the properties and creating nodes and storing values within it .

 

3 replies

Level 4
September 21, 2022

you can make your text fields hidden and when the dialog will be loaded you can read their previously authored data; if any value is authored,  programmatically click the multifield add button in new multi fields and populate it.

 

here is what we did for a similar scenario:

 

(function ($, Coral) {
"use strict";
$(document).on("dialog-ready", () => {

Coral.commons.ready(this, () => {
const existingtextfield = $(".coral-Form-field[name='./existingtextfield']").val();
const newMultiField = $("coral-multifield[data-granite-coral-multifield-name='./newMultiFields']");
const newMultiFieldLength = $(newMultiField).find("coral-multifield-item").length;

if (!newMultiFieldLength &&existingtextfield) {

$(newMultiField).find("button[coral-multifield-add]").click();
async function populateMultifieldItem() {
await new Promise(resolve => setTimeout(resolve, 500));
$(newMultiField).find(".coral-Form-field[name='./newMultiFields/item0/./path']").val(existingtextfield);
}
populateMultifieldItem();
}

//hiding all fields with below custom class authored
$(".hide-dialog-field").each(function () {
$(this).closest(".coral-Form-fieldwrapper").hide();
});
});

});

$(document).on("click", ".cq-dialog-submit", function (e) {
$(".coral-Form-field[name='./existingtextfield']").val("");
});

})(jQuery, Coral);

 

Level 4
September 21, 2022

but using this we need to open the content dialog box to run the changes

 

in the requirement, I will not open the dialog box to change anything

Level 4
September 21, 2022

you'll have to add support from backend as well for both old and new property.

if new is not there then put a check if old one is there and show the content based on that 

ksh_ingole7
Community Advisor
Community Advisor
September 21, 2022

Hi @rahul234dabas 

 

We had a similar scenario when we migrated from Coral UI 2 to Coral UI 3, where in we had to convert data that was stored in JSON format to nodes.

 

Write a Servlet that queries and fetches all your existing multifield nodes, stores the existing data in some Data structure and create nodes for Multifield. 

 

Below code would help you to convert it from JSON to Nodes. You might have to alter logic to first fetch your existing singular node data and then convert it to multifield nodes.

 

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/MultifieldConvertCoral2to3Servlet.java

 

Thanks,

K**bleep**ij

rahul234dabasAuthorAccepted solution
Level 4
September 22, 2022

Doing this via groovy Script now ,

I am fetching the properties and creating nodes and storing values within it .