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 :
Microsoft Dynamics CRM (Archived)

Accessing QuickView Form using Javascript

(0) ShareShare
ReportReport
Posted on by 1,848

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

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hello MN,

    Does the lookup field has any value?

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

    Cheers!

    Pedro Pisco

  • MNarmeen Profile Picture
    1,848 on at

    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?

  • MNarmeen Profile Picture
    1,848 on at

    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.

  • Suggested answer
    Community Member Profile Picture
    on at

    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

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

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


  • MNarmeen Profile Picture
    1,848 on at

    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.

  • MNarmeen Profile Picture
    1,848 on at

    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?

  • Community Member Profile Picture
    on at

    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

  • jimas1908 Profile Picture
    15 on at

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

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 August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
TNJ_CRM_Team Profile Picture

TNJ_CRM_Team 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans