Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Accessing QuickView Form using Javascript

Posted on by 1,846

Hi Experts,

I want to assign the value from a QuickViewForm to a field on the form using below code.

My custom field name: new_primary

QuickViewFormName: accountcard

function getAttributeValue() {
    var quickViewControl = Xrm.Page.ui.quickForms.get("accountcard");
    if (quickViewControl != undefined)
    {
        if (quickViewControl.isLoaded())
        {
            // Access the value of the attribute bound to the constituent control
            var myValue = quickViewControl.getControl(0).getAttribute().getValue();
            Xrm.Page.getattribute("new_primary").setValue(myValue);
            return;
        }
        else
        {
            // Wait for some time and check again
            setTimeout(getAttributeValue, 10);
        }
    }
    else
    {
        Xrm.Page.getattribute("new_primary").setValue("No Value");
        return;
    }    
}


This returns No Value to my custom field. What am I doing wrong? why is it not accessing the quick view form ?quickform.PNG

*This post is locked for comments

  • jimas1908 Profile Picture
    jimas1908 15 on at
    RE: Accessing QuickView Form using Javascript

    Debugging a similar problem that i had with a client's CRM installment, i figured out that the UI object did not have a reference to the quickForms object.

    The problem was located that the client had enabled the Legacy Forms options, instead of using TurboForms.

    It is mentioned here : docs.microsoft.com/.../formcontext-ui-quickforms

    Enabling TurboForms solved the problem.

    A guide can be found here : https://carldesouza.com/enable-and-disable-turbo-forms-in-dynamics-365/

    Just to mention you can access the quickforms either by XRM.Page or formcontext(the modernised way).

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Accessing QuickView Form using Javascript

    Hello MN,

    If it gave you the getAttribute error, it means it worked as expected, since it passed the verification "if (quickViewControl.isLoaded())".

    This means that the getControl is getting null, so you might need to verify if the control is null and why.

    Cheers!

    Pedro Pisco

  • MNarmeen Profile Picture
    MNarmeen 1,846 on at
    RE: Accessing QuickView Form using Javascript

    Goutam,

    Thankyou for the code but the code doesnot get past this function

    function getAttributeValue() {

                   var quickViewControl = Xrm.Page.ui.quickForms.get("accountcard");

                   if (quickViewControl != null) {

                       setTimeout(function () {

                           quickViewControl.refresh();

                           setTimeout( SetfieldValueFromquikView(),2000);

                       }, 1000);

                   }

               }

    When I tried it by checking it   if (quickViewControl == null) it calls the next function. That means it is not getting the quickview form as the function is called before it renders. Any suggestion to resolve this issue?

  • MNarmeen Profile Picture
    MNarmeen 1,846 on at
    RE: Accessing QuickView Form using Javascript

    Dear Pedro,

    I tried your code but it didnt work. I called the getAttribute function onChange of the dummyfield and called the fireField function on change of Potential Customer. It gave me an error on getAttribute function.

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Accessing QuickView Form using Javascript

    Hi ,

    Its strange , try to increase time out around 2000 or 3000. If it does not work try with below code.

                function getAttributeValue() {
                    var quickViewControl = Xrm.Page.ui.quickForms.get("accountcard");
                    if (quickViewControl != null) {
                        setTimeout(function () {
                            quickViewControl.refresh();
                            setTimeout( SetfieldValueFromquikView(),2000);
                        }, 1000);
                    }
                }
    
    
                function SetfieldValueFromquikView()
                {
                    var quickViewControl = Xrm.Page.ui.quickForms.get("accountcard");
                    if (quickViewControl != undefined)
                    {
                        if (quickViewControl.isLoaded())
                        {
                            // Access the value of the attribute bound to the constituent control
                            var myValue = quickViewControl.getControl(0).getAttribute().getValue();
                            Xrm.Page.getattribute("new_primary").setValue(myValue);
                            return;
                        }
                        else
                        {
                            setTimeout(SetfieldValueFromquikView,1000);
                        }
                     
                    }
                    else
                    {
                        Xrm.Page.getattribute("new_primary").setValue("No Value");
                        return;
                    }
                }


  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Accessing QuickView Form using Javascript

    Hello MN,

    If the function is on the OnChange event, makes sense, because your script runs before the quick form is rendered.

    Try the following:

    Create another function like:

    function fireField()

    {

       Xrm.Page.getAttribute("<anyfield_dummyfield>").fireOnChange();

       setTimeout(getAttributeValue, 10);

    }

    Add this function (fireField) on the onChange of the Potential Customer field.

    Then, your function, the getAttributeValue() add it to the <anyfield_dummyfield>

    This will run twice. The first (fireOnChange) will fail, the second will that contains the timeout will get the value that you need.

    Let us know if it worked.

    Cheers!

    Pedro Pisco

  • MNarmeen Profile Picture
    MNarmeen 1,846 on at
    RE: Accessing QuickView Form using Javascript

    Yes Pedro, it has the Potential Customer , which is the lookup field as well as the Primary Contact which is what I want to retrieve. Both fields have data inside.

    Im calling this function on onChange of Potential Customer Field.

  • MNarmeen Profile Picture
    MNarmeen 1,846 on at
    RE: Accessing QuickView Form using Javascript

    Thank you Goutam, Im not getting any error. Im calling this onChange of Potential Customer field , which is also a LookupField for the quickview form. The data is already loaded into the field when existing record is opened. It is taking me to the last 'else' part which means its not getting the quick view form control. How to make sure it gets it?

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Accessing QuickView Form using Javascript

    Hello MN,

    Does the lookup field has any value?

    If does not have, the quickform control will be undefined.

    Cheers!

    Pedro Pisco

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Accessing QuickView Form using Javascript

    Hi ,

    Which event you are triggering the function ?

    Are you getting any error?

    Make sure the form is loaded completely if you are using onload event. You may add setTimeout to call the function.

    Seems the quick view control is getting null and its not loaded and that's why value has not been set . I would suggest try to debug the code to find the root cause.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,188 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,030 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans