Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Automatically save and reload form based on field value

$
0
0

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:

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

FormSwitcher._redirectToForm = function (formName, tryDefault) {
    varcurrentForm = Xrm.Page.ui.formSelector.getCurrentItem();
    varavailableForms = 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 (variinavailableForms) {
            varform = availableForms[i];
            // try to find a form based on the name
            if (form.getLabel().toLowerCase() == formName.toLowerCase()) {
                form.navigate(); // redirect once we find it
                returntrue;
            }
        }
    }
    else {
        returnfalse;
    }

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

    returnfalse;
}

functionFormOnLoad()
{
    varcasetype_INFORMAL = 100000000;
    varcasetype_FORMAL = 100000001;
    varcasetype = Xrm.Page.getAttribute('new_casetype').getValue();

    switch (casetype)
    {
        casecasetype_INFORMAL:
            FormSwitcher._redirectToForm("Informal Case", true);
            break;
        casecasetype_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)


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images