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);
  • Suggested answer
    Milansinh Raj Profile Picture
    230 on at
    RE: Access field value from quick view and setValue in form field

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

  • Divyang Shukla Profile Picture
    355 on at
    RE: Access field value from quick view and setValue in form field

    Hi Milansinh Raj, it is custom JS

  • Milansinh Raj Profile Picture
    230 on at
    RE: Access field value from quick view and setValue in form field

    Hi Divyang Shukla,

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

    or this is your custom JS file?

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Access field value from quick view and setValue in form field

    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 

  • Suggested answer
    Divyang Shukla Profile Picture
    355 on at
    RE: Access field value from quick view and setValue in form field

    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

  • a33ik Profile Picture
    84,329 Most Valuable Professional on at
    RE: Access field value from quick view and setValue in form field

    Hello,

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

  • Divyang Shukla Profile Picture
    355 on at
    RE: Access field value from quick view and setValue in form field

    Hi,

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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,099 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,884 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans