Wednesday, March 25, 2015

Access Quick View Form values in JavaScript

Generally if want to access any control or attribute in CRM form script you will use control or attribute name.. For Quick form it is little bit complicated.

If I have Quick form for custom entity new_manufacture, and I added this quick form in new_car entity form.

To access new_manufacturer quick form in car entity form I need to use Quick form name, entity name and attribute name to get value.

To access in JavaScript Quick view, control name should be like
QuickFormname_QuickFormname_EntityName_AttributeName



My Quick Form name is : manufactureQuickView
Entity Name : new_manufacture
Attribute: new_Country

if (Xrm.Page.getControl('manufactureQuickView_manufactureQuickView_new_manufacture_new_Country') != null)
{
            var manfCountyctrl = Xrm.Page.getControl('manufactureQuickView_manufactureQuickView_new_manufacture_new_Country');
            var country = manfCountyctrl.getAttribute().getValue();


        }


7 comments:

  1. i seen the sample of javascript for getting quickview details.

    now i need same in account form. in account form contact quickview is there. so need the contact email,telephone values

    ReplyDelete
  2. i am getting null value for the below script using

    function getQuickView()
    {
    if (Xrm.Page.getControl("contactquickform_contactquickform_contact_emailaddress1") != null)
    {
    var manfCountyctrl = Xrm.Page.getControl("contactquickform_contactquickform_contact_emailaddress1");

    var country = manfCountyctrl.getAttribute().getValue();
    alert(country);
    //var manfCountyctrl2 = window.parent.Xrm.Page.getControl("contactquickform_contactquickform_account_telephone1");
    // var country2 = manfCountyctrl2.getAttribute().getValue();


    // alert(country2);

    //alert(Xrm.Page.getControl("contactquickform_contactquickform_contact_emailaddress1").getAttribute().getValue());
    }


    }

    ReplyDelete
  3. Hi,
    There are multiple possibilities

    1. your quick form name is not correct
    check what name you are giving to quick form, when it is added on child entity form.
    JavaScript is case sensitive so this name should be same as given.

    2. Whatever field you are accessing is not present on quick view form

    3. Even field is present.. but there is not any data.


    ReplyDelete
  4. Note that even though it works in CRM 2013/2015, it is unsupported customizations and it does not work in CRM 2016.

    ReplyDelete
    Replies
    1. It will work in unsupported customization in CRM 2016
      document.getElementById("QuickView_account_QuickView_account_account_telephone1_i").getAttribute("defaultvalue")

      Delete
  5. Here is how to get it working using a supported method in CRM 2016:

    http://blogs.msdn.com/b/emeadcrmsupport/archive/2015/09/24/dynamics-crm-how-to-access-a-quickform-component-via-jscript-in-turbo-forms.aspx

    ReplyDelete
  6. it is getting null i am having field on form, name i gave is also correct
    function gettingQVFvalues() {
    if (Xrm.Page.getControl("Quick_Quick_new_testsolution_new_map11") == null) {
    alert("null");
    }
    else {
    var manfCountyctrl = Xrm.Page.getControl("Quick_Quick_new_testsolution_new_map11");
    var country = manfCountyctrl.getAttribute().getValue();
    alert(country);
    }
    }

    this is code i used

    ReplyDelete