Skip to main content

Notifications

Dynamics 365 general forum
Suggested answer

Update form field from lookup field within quickview

Posted on by 2
On my main form I have a lookup field called /Name/, when the user selects /Name/ a quickview is displayed, one of the fields within the quickview is a lookup field called /Course_Information/. I am trying to take /Course_Information/ and write that value into a field on the main form called /courseinformation/. 

Nothing happens the first time I select a /Name/ from the lookup field. When I remove the item /Name/ and select the /Name/ a second time, the below code then copies the quickview field into the form field.. Im unsure why this is happening. Any support would be appreciated 
 
function OnLoad1(executionContext) {      Xrm.Page.getAttribute(/nelep_studentapplication/).addOnChange(getQuickViewForm);}function getQuickViewForm(executionContext){var formContext = executionContext.getFormContext();var quickViewControl = formContext.ui.quickForms.get(/QuickviewControl1682435827537/);if (quickViewControl != undefined) {        if (quickViewControl.isLoaded()) {// Access the value of the attribute bound to the constituent controlvar CourseInformation = quickViewControl.getControl(0).getAttribute().getValue();var CourseID = CourseInformation[0].id;var CourseName = CourseInformation[0].name;var CourseType = CourseInformation[0].entityType;formContext.getAttribute(/courseinformation/).setValue([{ id: CourseID, name: CourseName, entityType: CourseType }]); // Unit Group                        return;        }        else {setTimeout(getQuickViewForm, 1, executionContext);        }    }    else {        Xrm.Utility.alertDialog(/No data to display in the quick view control./);        return;    }}
 
  • Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Update form field from lookup field within quickview
    Hi Partner,
    Was my answer helpful? 
    If it was helpful, can you verify it?
    If you have any questions, please feel free to contact me.
    Regards,
    Leah
  • Suggested answer
    Leah Ju Profile Picture
    Leah Ju Microsoft Employee on at
    Update form field from lookup field within quickview
    Hi Partner,
    Did you put the code on the onload event?
    --Try to add the web resource  directly on the field onchange event.
    Based on you description and code, you need get 'courseinformation' value from name entity and set 'Course_Information' field on current entity.
    --Essentially, you are trying to copy a field value from the parent entity (Name) to populate a field value in the current entity.
    So you can retrieve name entity to get value not through quick view control:

    Xrm.WebApi.retrieveRecord("Nameentity", "nameid", "?$select=_lookupname_value").then(
        function success(result) {
            console.log(result);
            // Columns
            var incidentid = result["incidentid"]; // Guid
            var accountid = result["_accountid_value"]; // Lookup
            var accountid_formatted = result["_accountid_value@OData.Community.Display.V1.FormattedValue"];
            var accountid_lookuplogicalname = result["_accountid_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
        },
        function(error) {
            console.log(error.message);
        }
    );
    Or you can try to use workflow to achieve you goal easily.
  • ConnollyZ Profile Picture
    ConnollyZ 2 on at
    Update form field from lookup field within quickview
    function OnLoad1(executionContext) {
       
       Xrm.Page.getAttribute("nelep_studentapplication").addOnChange(getQuickViewForm);
        
    }
    function getQuickViewForm(executionContext)
    {
    var formContext = executionContext.getFormContext();
    var quickViewControl = formContext.ui.quickForms.get("QuickviewControl1682435827537");

        if (quickViewControl != undefined) {
            if (quickViewControl.isLoaded()) {
                // Access the value of the attribute bound to the constituent control
                var CourseInformation = quickViewControl.getControl(0).getAttribute().getValue();
                var CourseID = CourseInformation[0].id;
                var CourseName = CourseInformation[0].name;
                var CourseType = CourseInformation[0].entityType;
            
                formContext.getAttribute("courseinformation").setValue([{ id: CourseID, name: CourseName, entityType: CourseType }]); // Unit Group
                
                return;
            }
            else {setTimeout(getQuickViewForm, 1, executionContext);
            
            }    
        }
        else {
            Xrm.Utility.alertDialog("No data to display in the quick view control.");
            return;
        }
    }
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,469 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans