web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Switching Forms based on Option Set

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    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);

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,916 on at

    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");

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans