Reputation: 31
For a certain aspect of functionality, I require the need to pull a value from a quick view form on an entity "Course request" form. The quick view form is of the "programme" entity and includes details on Member and Non-member price.
I need to retrieve the "member price" value and set a corresponding field on the parent form to this value. I have the below code to do this, however this does not seem to work.
Quick View Form is called: Course: Programme Details - Quick View
function getPrice(){
if (Xrm.Page.getControl('Course: Programme Details - Quick View_Course: Programme Details - Quick View_programme_MemberPrice') != null)
{
var priceQuickControl = Xrm.Page.getControl('Course: Programme Details - Quick View_Course: Programme Details - Quick View_programme_MemberPrice');
var price = priceQuickControl.getAttribute("memberprice").getValue();
//var newEmailfield = Xrm.Page.getAttribute("MemberPrice");
var priceCourseRequest = Xrm.Page.getAttribute("memberprice").setValue(price);
console.log(priceCourseRequest);
}
else{
return null;
}
}
Upvotes: 0
Views: 2216
Reputation: 22836
Make sure you are using Name of Quick view form instead of label, as name cannot have space like you used.
Also, you may need to use isLoaded
method to ensure the complete rendering and setTimeout
for retry. Read more
function getAttributeValue(executionContext) {
var formContext = executionContext.getFormContext();
var quickViewControl = formContext.ui.quickForms.get("<QuickViewControlName>");
if (quickViewControl != undefined) {
if (quickViewControl.isLoaded()) {
// Access the value of the attribute bound to the constituent control
var myValue = quickViewControl.getControl(0).getAttribute().getValue();
console.log(myValue);
// Search by a specific attribute present in the control
var myValue2 = quickViewControl.getControl().find(control => control.getName() == "<AttributeSchemaName>").getAttribute().getValue();
console.log(myValue2);
return;
}
else {
// Wait for some time and check again
setTimeout(getAttributeValue, 10, executionContext);
}
}
else {
console.log("No data to display in the quick view control.");
return;
}
}
Upvotes: 0