Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

Retrieve Quick View Form Value - Dynamics CRM JavaScript

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


question from:https://stackoverflow.com/questions/65923547/retrieve-quick-view-form-value-dynamics-crm-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...