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 ?
*This post is locked for comments
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).
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
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?
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.
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; } }
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
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.
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?
Hello MN,
Does the lookup field has any value?
If does not have, the quickform control will be undefined.
Cheers!
Pedro Pisco
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,188 Super User 2024 Season 2
Martin Dráb 230,030 Most Valuable Professional
nmaenpaa 101,156