首页 > 解决方案 > 检索快速查看表单值 - Dynamics CRM JavaScript

问题描述

对于功能的某个方面,我需要从实体“课程请求”表单上的快速查看表单中提取一个值。快速查看表属于“计划”实体,包括有关会员和非会员价格的详细信息。

我需要检索“会员价格”值并将父表单上的相应字段设置为该值。我有以下代码来执行此操作,但这似乎不起作用。

快速查看表单被称为:课程:计划详细信息 - 快速查看

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


标签: javascriptdynamics-crmmicrosoft-dynamicswebresource

解决方案


确保您使用的是快速查看表单的名称而不是标签,因为名称不能像您使用的那样有空格。

此外,您可能需要使用isLoaded方法来确保完整呈现setTimeout并重试。阅读更多

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

推荐阅读