We have a custom entity that has multiple forms depending on an optionset value on the form.
When the page loads for an existing record a "changeForm" function is called last and evaluates the form that is loaded versus the value of the optionset field. If the form type does not correspond to the option set navigation is changed to the correct form. This works fine for existing records .
For a new record the user selects the value desired for the optionset and like above navigation proceeds to the correct form based on the optionset value chosen. However, the on-load event for the correct form loads and it calls the same change event but this time the value chosen by the user seems to be lost and is now undefined. When this happens the code is set to default to a specific form. This only seems to happen with one optionset type. Is there a way to maintain what the user chose ?
*This post is locked for comments
When the form on the state "Create", you can't just redirect the value to another form. The easiest way is you need to force save the entity first and then you can redirect it to another form. Or else you need to store the value on the sessionStorage and your code will have to look on that one if exists.
developer.mozilla.org/.../sessionStorage
So what I think is on your optionset change:
if(Xrm.Page.ui.getFormType() === 1){
sessionStorage.setItem("type", Xrm.Page.getAttribute("new_type").getValue();
}
Then on your form on load:
var type = Xrm.Page.getAttribute("new_type").getValue() || sessionStorage.getItem("type");
//because you said that your type is empty, then you need to set the attribute if type is not empty
var typeValue = Xrm.Page.getAttribute("new_type").getValue();
if(!typeValue && type){
Xrm.Page.getAttribute("new_type").setValue(type);
//clear the storage either have value or not have value
sessionStorage.removeItem("test");
}
Hi,
You can keep your code to just called for the existing record by checking form type, and onchange of the radio button you can open specific form directly by passing form id something like below
var parameters = {};
parameters["formid"] = "Form GUID";
Xrm.Utility.openEntityForm(name,id,parameters);
Hi,
For the new record, the values selected are not actually stored so it is expected that your function will not find the previously selected value. Ideally you shouldn't be running the function on create form i.e. put a check that it doesn't run on create form.
What do you mean when you say "This only seems to happen with one optionset type.". Is it not working on specif optionset value? If yes then you need to check the value returned and the corresponding form name. If you are not handling that value in your logic then it won't work.
Hope this helps.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156