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...
Unanswered

Populate a field on load

(0) ShareShare
ReportReport
Posted on by 10

Hi,

 I want to populate a field which is  on contact email field  on another entity pde .

pde is related to case and there is no relation from pde to contact.

Thanks

I have the same question (0)
  • Guido Preite Profile Picture
    54,086 Moderator on at

    if there is a relation between case or contact (or one between case, another entity and after contact) it is possible with some javascript (Xrm.WebApi or similar)

    hope it helps

  • EKL Profile Picture
    10 on at

    Hello Guido,

    With javascript, I got the following code and the field to populate is written in a loop in One To Many Relationships, how to populate field and which line I need to assign.

    Is it after the for loop.

    function populateCaseFieldsOnPDE(executionContext)

    {

      debugger;

      var formContext = executionContext.getFormContext();

      var associatedCase = formContext.getAttribute("har_associatedcase").getValue();

      if(associatedCase != null)

      {

      var caseId = formContext.getAttribute("har_associatedcase").getValue()[0].id.slice(1, -1);

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Utility.getGlobalContext().getClientUrl() + "/api/data/v9.2/incidents(" + caseId + ")?$select=har_klscodepostcode,har_siteaddress,har_customercontactname,har_sitecontactname&$expand=har_incident_contact_Case($select=emailaddress1)", false);

    req.setRequestHeader("OData-MaxVersion", "4.0");

    req.setRequestHeader("OData-Version", "4.0");

    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

    req.setRequestHeader("Accept", "application/json");

    req.setRequestHeader("Prefer", "odata.include-annotations=*");

    req.onreadystatechange = function () {

    if (this.readyState === 4) {

    req.onreadystatechange = null;

    if (this.status === 200) {

    var result = JSON.parse(this.response);

    console.log(result);

    // Columns

    var incidentid = result["incidentid"]; // Guid

    var har_klscodepostcode = result["har_klspostcode"]; // Text

    var har_siteaddress = result["har_siteaddress"]; // Multiline Text

    var har_customercontactname = result["har_customercontactname"]; // Text

    var har_sitecontactname = result["har_sitecontactname"]; // Text

    // One To Many Relationships

    for (var j = 0; j < result.har_incident_contact_Case.length; j++) {

    var har_incident_contact_Case_emailaddress1 = result.har_incident_contact_Case[j]["emailaddress1"]; // Text

    }

    } else {

    console.log(this.responseText);

    }

    }

    };

    req.send();

      }

    }

    Thanks

  • Leah Ju Profile Picture
    Microsoft Employee on at

    Hi Partner,

    What is the relationship between these three entities?

    I know that case and pde are 1:N relationship, what about case and contact?

    1:N or N:1?

    Based on your code, case and contact are 1:N, so one pde has one case, but one case related to multiple contacts, which contact's email do you need?

    The 1:N relationship you used is custom?

    There are OOB N:1 relationships between case and contact, why not use it?

    pastedimage1681977492745v2.png

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
Martin Dráb Profile Picture

Martin Dráb 47 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans