1 Jan’18

Dynamics 365, EnterprisePrepopulating Lookup and dropdown fields on a Form in D365 CRM Portals using JS

Overview:

In this blog we will see how we can prepopulate lookup and dropdown (option set) fields on an Entity form in D365 CRM Portals using JS.

Pre-Requisites:

  1. D365 CRM Portals
  2. D365 CRM Environment

Introduction

We know that if we want to prepopulate a lookup or a dropdown field on a form in CRM Portals the best method is to use Entity Form Metadata. But there is an alternative way to prepopulate the Lookup and dropdown (Option set) fields on an Entity form in D365 CRM Portals using JS.

Scenario:

To implement the functionality of prepopulating a lookup field we will be using the account lookup field on the CRM entity form based on the value entered in the contact field for a created opportunity in the partner portal. For the prepopulating the dropdown field we will be using the opportunity status field.

Process:

  • First of most we will see how to prepopulate the lookup field on the entity form based on the value entered in another field. As mentioned in the above scenario we need to prepopulate an account field on an opportunity form based on the value present in the contact field.
  • To insert a value into a lookup field using JS(jquery) we need the following information as mentioned below.
    1. The field value to be displayed. For eg. Account full name.
    2. The GUID if the record to be displayed. For eg. GUID of the account record.
    3. The logical name of the entity. For eg. Logical name of the account entity.
  • Now we will see how to get these details form the existing information we have on the opportunity form. When we open an opportunity record, on the details page in the URL section we get the id of the opportunity record as shown below

  • We will insert this id into the fetch xml using liquid template to obtain details of the contact related to the following opportunity record as shown below.

  • As shown above we have used the opportunity id in the fetchxml to get the contact details. Once we have obtained the contact details from which we will be using the contact name value in the next fetchxml to get the related account information.
  • In the following below shown fetchxml we will get the value and the id of the account record to be inserted.

Once we get the account record details we will write the jquery in the following manner to insert the value into the lookup field.
Jquery syntax:

<script>
$(“form_attributeid_name”).val(“record_value”);
$(“form_attributeid”).val(“record_GUID”);
$(“form_attributeid_entityname”).val(“entity_logicalname”);
</script>

  • Once we publish the liquid code we will see that the account field on the opportunity form is prepopulated with the value related to the value present in the contact field.
  • For prepopulating the dropdown(option set) field we need the option set value of the record to be displayed. To set the value in the option set we will write the following jquery.
    $(form_attributeid).val(“attribute_optionsetvalue”);

Hope you all find this blog helpful. Happy coding in CRM portals.

Written by

Team Member

CloudFronts

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.

Want to streamline your business processes?

  • This field is for validation purposes and should be left unchanged.

Recent Articles

  • Commands to Import .bacpac file to D3FOE SQL Server

    14 May’ 2018

    Introduction: This blog article will explain how to import a .bacpac file to Microsoft SQL Server which is created from ...

    Read more
  • [Solved] – Backspace not working in HTML Web Resources

    11 May’ 2018

    Issue: When we use a HTML web resource in Dynamics 365 CRM forms or even as a separate navigation, we sometimes face is...

    Read more
  • Dynamics 365 Tip: Sending Emails using Unified Interface

    10 May’ 2018

    Introduction: The unified client which was released D365 V9 had a very refreshing UI and lots of features. One of the b...

    Read more
  • Filtering Records on BPF unlike on Form – D365

    10 May’ 2018

    Introduction: Working with D365 is best when you’re trying to use as much OOB stuff as possible. Simplest configurati...

    Read more
  • Filter records in gallery control based on value selected in other gallery control in PowerApps.

    10 May’ 2018

    Introduction: This blog explains how to Filter records in gallery control based on value selected in other gallery cont...

    Read more