web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Access field value from quick view and setValue in form field

(0) ShareShare
ReportReport
Posted on by 35

Hi,

I am trying to get a field value from Quick View form and need to set that value in a field in the main form. In the main form properties I have added this js in event library and  in Event Handlers added sdk.formOnLoad to load this form onLoad.

I didnt do any event handlers in the fields where the value should set from quickview. 

I am new to javascript, I am getting this error now "Web resource method does not exist: formOnLoad"

I have to mention that field types are dates.

Thanks for your help

 

var Sdk = window.Sdk || {};
(function () {
    'use strict';
    // Code to run in the form OnLoad event
    this.formOnLoad = function (executionContext)
 {
        var formContext = executionContext.getFormContext();
        formContext.getAttribute("startdate").addOnChange(getAttributeValue);
    }
   
    function getAttributeValue(executionContext){
        var formContext = executionContext.getFormContext();
        var quickViewControl = formContext.ui.quickForms.get("Opp_Opp_Product_QuickViewForm");
        if(quickViewControl != undefined){
            if(quickViewControl.isLoaded()){
                var oppProdStartDate = quickViewControl.getControl("pde_start_date_dat").getAttribute().getValue();
                alert(oppProdStartDate);
                formContext.getControl("startdate").getAttribute().setValue(oppProdStartDate);
            } else {
                // Wait for some time and check again
                setTimeout(getAttributeValue, 10, executionContext);
            }

        } else {
            formContext.getAttribute("startdate").setValue("No value");
            return;
        }
        }
}).call(Sdk);
I have the same question (0)
  • Divyang Shukla Profile Picture
    355 on at

    Hi,

    Please refer community.dynamics.com/.../769379.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Can you please provide a screenshot that demonstrates how you registered the onload event handler on the form?

  • Suggested answer
    Divyang Shukla Profile Picture
    355 on at

    Sure, please refer below steps.

    1. Create JavaScript Web resource
    2. Go to Form customization and open the form (Settings -> Customization -> Select Entity -> Forms)
    3. Open form property -> Click on Add and look for the Web resource you have created.
    4. Select the Control and event respectively.

    pastedimage1662056480885v1.png

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi smar.sus,

    The quick view form control is based on the lookup field, A field in the Quick View control is a field in another entity to which the lookup field refers.

    If you want to a field value from Quick View form, you can get the field based on the lookup directly.

    In my example:

    pastedimage1662099601098v1.png

    (1)js code:

    unction getLookupDetails(executionContext) {
    	var formContext = executionContext.getFormContext();
    	//get lookup attribute
    	var lookup = formContext.getAttribute("new_shippingcodeid").getValue();//new_shippingcodeid is logic name of the lookup
    
    	if(lookup!= null)
    	{
    		// Getting the GUID of the lookup record
    		var Id = lookup[0].id;
    		// Getting Name of the lookup record
    		var Name = lookup[0].name;
    		// Getting Entity Name of the lookup which entity, the lookup record is belonging to.
    		var EntityType = lookup[0].entityType;
    
    		//Retrieve parent records based on the lookup
    		Xrm.WebApi.online.retrieveRecord(EntityType, Id, "?$select=new_date").then(
    			function success(result) {
    				console.log(result);
    				// Columns
    				var new_shippingcodeid = result["new_shippingcodeid"]; // Guid
    				var new_date = result["new_date"]; // Date Time
    				var new_date_formatted = result["new_date@OData.Community.Display.V1.FormattedValue"];
    
    				if (new_date != null) {
    					var getDate = new Date(new_date);
    					formContext.getAttribute("new_dateline").setValue(getDate);//populate date field of the mail form
    				}
    			},
    			function (error) {
    				console.log(error.message);
    			}
    		);
    	}
    }

    (2)Result:

    pastedimage1662099844384v2.png

    Note: you can build webapi with the 'Dataverse Rest Builder' tool easily:

    https://github.com/GuidoPreite/DRB 

  • Milansinh Raj Profile Picture
    230 on at

    Hi Divyang Shukla,

    Have you edited the OOB JS and added your function inside OOB JS ?

    or this is your custom JS file?

  • Divyang Shukla Profile Picture
    355 on at

    Hi Milansinh Raj, it is custom JS

  • Suggested answer
    Milansinh Raj Profile Picture
    230 on at

    can you try this line "function formOnLoad(executionContext)" instead of  "this.formOnLoad = function (executionContext)"

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans