Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer Service forum

Client API, retrieve records

(0) ShareShare
ReportReport
Posted on by 1,942

Hi All,

I am using the following code to retrieve field value and retrieving another record data and writing to the form. Can anyone help me with troubleshooting please.

function callsetvalue(executionContext){
debugger;
var formContext = executionContext.getFormContext();
var record_id = formContext.getAttribute("regardingobjectid").getValue()[0].id;
Xrm.WebApi.retrieveRecord("iis_project",record_id, "?$select=fullname,iis_primarycontactid_value").then(
function success(result){
var c_id = "result.iis_primarycontactid_value:";
},);
Xrm.WebApi.retrieveRecord("contact",c_id, "?$select=fullname,telephone2,mobilephone").then(
function success(result){
formContext.getAttribute("iis_customername").setValue(result.fullname);
formContext.getAttribute("iis_homephone").setValue(result.telephone2);
formContext.getAttribute("iis_mobilephone").setValue(result.mobilephone);},);
}

Categories:
  • Suggested answer
    Vighnesh Profile Picture
    Vighnesh 1,942 on at
    RE: Client API, retrieve records

    Verified solution: Since I cannot verify the solution that was posted by me, I'm writing here

    Requirement: Pre-populate data on the Customer touchpoint activity record based on the contact selected on the project form.

    System entities: Contact

    Custom entities: Project, Customer Touchpoint(activity entity type)

    Relationship: 1 Project-N Customer touchpoint

     

    Code used (Note: Enable executionContext as first parameter in the form properties)

    function callsetvalue(executionContext){
    var formContext = executionContext.getFormContext();
    if(formContext.ui.getFormType() ==1){
    var record_id=formContext.getAttribute("regardingobjectid").getValue()[0].id;;
    Xrm.WebApi.retrieveRecord("iis_project",record_id,"?$select=_iis_primarycontactid_value,velosio_projectnumber").then(
    function get_pvalue(data){
    var cnt_id= data["_iis_primarycontactid_value"];
    Xrm.WebApi.retrieveRecord("contact",cnt_id,"?$select=contactid,fullname,telephone2,mobilephone").then(
    function get_cvlaue(success){
    var cust=[];
    cust[0]= new Object();
    cust[0].id= success["contactid"];
    cust[0].name= success["fullname"];
    cust[0].entityType= "contact";
    var home_phone=success["telephone2"];
    var mobile_phone=success["mobilephone"];
    formContext.getAttribute("iis_customername").setValue(cust);
    formContext.getAttribute("iis_homephone").setValue(home_phone);
    formContext.getAttribute("iis_mobilephone").setValue(mobile_phone);
    });
    });
    }
    }

     

  • Vighnesh Profile Picture
    Vighnesh 1,942 on at
    RE: Client API, retrieve records

    Here is my updated code and it works for some extent. I receive the error saying "the value is not an array".

    Below is the updated code:

    function callsetvalue(executionContext){

    debugger;

    var formContext = executionContext.getFormContext();

    var record_id=formContext.getAttribute("regardingobjectid").getValue()[0].id;;

    Xrm.WebApi.retrieveRecord("iis_project",record_id,"?$select=_iis_primarycontactid_value").then(

    function success(data){

    var cnt_id= data._iis_primarycontactid_value;

    Xrm.WebApi.retrieveRecord("contact",cnt_id,"?$select=lastname,fullname,telephone2,mobilephone").then(

    function send(success){

    var full_name= success.fullname;

    var home_phone= success.telephone2;

    var mobile_phone= success.mobilephone;

    formContext.getAttribute("iis_customername").setValue(full_name);

    formContext.getAttribute("iis_homephone").setValue(home_phone);

    formContext.getAttribute("iis_mobilephone").setValue(mobile_phone);

    });

    });

    }

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,401 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans