3 weeks ago
Hi Everyone,
I haven an issue with VariantManagement from sap.ui.fl library where it creates variant without any problem on `save` event. After it is saved, if i try to update it by adding new filters on screen but it fails to update variant. There is no error or anything on screen. When i check network tab, i can see request during initial save for creation but not with update. Overrite attribute is set to true and same codes are triggered in save.
sample:
variantManagerXML.attachEvent("save", (event) => {
try {
const filterData = mainFilter.getData();
const mParameters = event.getParameters();
mParameters.contexts = {
content: JSON.parse(JSON.stringify(filterData))
};
this.byId("vm").setModified(true);
} catch (error) {
console.error("Error during save:", error);
}
});
Where can be the problem on update ?
Request clarification before answering.
Hi Bilen,
I was able to resolve the issue by ensuring that the variant data is persistently stored rather than being directly assigned to filterData. The key improvement was persisting variants in localStorage, merging new data with existing data before saving.
variantManagerXML.attachEvent("save", (event) => {
try {
const filterData = mainFilter.getData();
const mParameters = event.getParameters();
let currentVariantKey = mParameters.key || this.byId("vm").getCurrentVariantKey();
if (!currentVariantKey) return;
// Retrieve existing custom variants from localStorage
const customVariantData = JSON.parse(localStorage.getItem("customVariantData")) || {};
const existingVariant = customVariantData[currentVariantKey] || {};
// Merge new filter values with existing variant data
customVariantData[currentVariantKey] = {
...existingVariant,
XYZ: { values: [...filterData.XYZ.values] }
};
// Persist the updated variant only if overwriting is enabled
if (mParameters.overwrite) {
localStorage.setItem("customVariantData", JSON.stringify(customVariantData));
}
const sanitizedData = JSON.parse(
JSON.stringify(filterData, (key, value) =>
key === "values" && Array.isArray(value) ? JSON.stringify(value) : value
)
);
mParameters.contexts = {
content: JSON.stringify(sanitizedData)
};
mParameters.executeOnSelection = true;
} catch (error) {
console.error("Error during save:", error);
}
});
I hope this helps anyone else looking for a similar solution!
Best,
Nil
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
57 | |
10 | |
9 | |
8 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.