Hi Community,
How can I do in the new Freedom Ui so that the page does not close after saving a record?
I know the method in the old classic page, but I can't find the way to do it in the new Freedom ui.
Thank you in advance.
Like
This works, but does produce some odd results on some pages - for example the Case page shows several things once the CreatedOn is populated and it appears that the data isn't reloaded after the save. So you'd probably also have to do a reload in addition to this:
{ request: "crt.SaveRecordRequest", handler: async (request, next) => { request.preventCardClose = true; return next.handle(request); } }
Ryan
Ryan Farley,
Hi Ryan,
is there a way to stay on the page of a newly created Case record, but having the page reloaded after the case number has been generated?
Currently I'm just staying at the Case page, but the case number and resolution time don't show up.
Thank you in advance
Alex Parkhomchuk,
It works to follow up the save with a refresh. Something like this:
{ request: "crt.SaveRecordRequest", handler: async (request, next) => { // don't close page request.preventCardClose = true; const result = await next.handle(request); // reload if adding const cardState = await request.$context.CardState; if (cardState == "add" || cardState == "copy") { request.$context.executeRequest({ type: "crt.LoadDataRequest", $context: request.$context, config: { loadType: "reload", useLastLoadParameters: true }, dataSourceName: "PDS" }); } return result; } }
However, although it works, the URL still says it's in add mode (showing #Card/Cases_FormPage/add), even though it's not. A hacky alternative is to just navigate to the edit page of the case from the save.
{ request: "crt.SaveRecordRequest", handler: async (request, next) => { // don't close page request.preventCardClose = true; const result = await next.handle(request); // re-open in edit if adding const cardState = await request.$context.CardState; if (cardState == "add" || cardState == "copy") { const caseId = await request.$context.Id; request.$context.executeRequest({ type: "crt.UpdateRecordRequest", entityName: "Case", $context: request.$context, recordId: caseId }); } return result; } }
I tried changing the page to edit mode in the save (changing action and recordId in the modelInitConfigs), but this doesn't seem to do anything in the save, likely only works in the init
Ryan
Ryan Farley,
Did you ever find a way to effectively change the mode of the page from add to edit? I'm having an issue where I have a modal page with a list, and when it's open in add mode, trying to add child records results in the page "breaking".
The code checks if the page is in add/copy mode and will perform a save if so before continuing. The child records are added in the afterClosed async function of an OpenSelectionWindowRequest and they all get added to the system/database fine even in add mode, but when in add mode the page would show the associated list refreshing animation but never finish, and it would break all the buttons on the page (refresh, save, cancel, close etc) and would require refreshing the page to get working again - not something users could be expected to do every time!
The simplified code snippet:
request: "usr.AddRecordsFromSelection", handler: async (request, next) => { if(["add", "copy"].includes(await request.$context.CardState)) { // Save if creating a new parent const saveSucceeded = await request.$context.executeRequest({ type: "crt.SaveRecordRequest", preventCardClose: true, $context: request.$context }); if(!saveSucceeded) { return next?.handle(request); } } // Create the pop up window that will allow the user to select the records to add request.$context.executeRequest({ type: "crt.OpenSelectionWindowRequest", $context: request.$context, entitySchemaName: "UsrTest", filtersConfig: filtersConfig, features: { select: { multiple: true, selectAll: true, resultType: 'filter' // Return as filter so that we can use selectAll }, create: { enabled: false } }, afterClosed: async function (selectionFilter) { // Fetch all selected items const recModel = await sdk.Model.create("UsrTest"); const selectedRecs = await recModel.load({ attributes: ["Id"], parameters: [{ type: sdk.ModelParameterType.Filter, value: selectionFilter }] }); if(!selectedRecs || selectedRecs.length == 0) { return; } // for each loop & other logic skipped, just showing an example of what would be run here const result = await request.$context.executeRequest({ type: "crt.RunBusinessProcessRequest", processName: "UsrTestCreateRecord", processParameters: { Parent: await request.$context.Id, Child: selectedRecs[0], }, $context: request.$context }); } }); return next?.handle(request); }
I've tried performing a PDS refresh after the parent is saved and a few other things while fiddling with it, but it doesn't seem like anything makes it work as intended.
Harvey Adcock,
I do have code that sets a page in edit mode for a particular record Id, but I've only tried that in the crt.HandleViewModelInitRequest, never tried it outside of that, so no idea if it works after, just sharing so you can try (I suspect it doesn't work outside of the init, but something to play with I guess). The code looks like this:
{ request: "crt.HandleViewModelInitRequest", handler: async (request, next) => { request.$context.modelInitConfigs.forEach((config) => { if (config.action === "add") { config.action = "edit"; } if (config.name === "CfxSubscriptionCenterElementDS") { config.recordId = "1607c717-96aa-4b74-a090-f68a6b124170"; } }); return await next?.handle(request); } }
Ryan