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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Automatically save and reload form based on field value

(0) ShareShare
ReportReport
Posted on by 10

Hello,


I have read through a few previously forum questions and cannot quite find the exact answer I am looking for. I have a JS code to change the form based on a selected option set. I have this set OnLoad and OnSave events.

It is an Informal Case form and Formal Case form (with corresponding values in the "Case Type" field, to trigger the form change)

The code works, but I would like a little added flexibility. It will currently only work if the field is selected prior to loading, or if I change the field value and save the form. Is there a way I can have the form automatically save and refresh as the value is changed. If someone creates a new case from scratch, the "Case Type" field is blank, I would like the form to automatically change as soon as the Case Type field value is selected (not waiting for it to be done after saving).

Is there a way to do this? Can I add a piece of code to automatically save an update the form once the case value is selected? Is it possible with an OnChange event code.

My code:

var FormSwitcher = FormSwitcher || {};
FormSwitcher._defaultFormName = "Informal Case";

FormSwitcher._redirectToForm = function (formName, tryDefault) {
    var currentForm = Xrm.Page.ui.formSelector.getCurrentItem();
    var availableForms = Xrm.Page.ui.formSelector.items.get();

    // if we dont check to see if we're already on the form we'll get into an infinite loop
    if (currentForm.getLabel().toLowerCase() != formName.toLowerCase()) {
        for (var i in availableForms) {
            var form = availableForms[i];
            // try to find a form based on the name
            if (form.getLabel().toLowerCase() == formName.toLowerCase()) {
                form.navigate(); // redirect once we find it
                return true;
            }
        }
    }
    else {
        return false;
    }

    // nothing found, redirect to default
    if (tryDefault && currentForm.getLabel().toLowerCase() != FormSwitcher._defaultFormName) {
        return FormSwitcher._redirectToForm(FormSwitcher._defaultFormName, false);
    }

    return false;
}

function FormOnLoad()
{
    var casetype_INFORMAL = 100000000;
    var casetype_FORMAL = 100000001;
    var casetype = Xrm.Page.getAttribute('new_casetype').getValue();

    switch (casetype)
    {
        case casetype_INFORMAL:
            FormSwitcher._redirectToForm("Informal Case", true);
            break;
        case casetype_FORMAL:
            FormSwitcher._redirectToForm("Formal Case", true);
            break;
        default:
            FormSwitcher._redirectToForm(FormSwitcher._defaultFormName, false);
            break;
    }
}

Any help is appreciated--thanks! (I am using Microsoft Dynamics 365 Server Version 9.2)

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 Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 109 Super User 2026 Season 2

#2
Syed Aqib Raza Profile Picture

Syed Aqib Raza 88

#3
ParthPatel249 Profile Picture

ParthPatel249 82

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans