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

Notifications

Announcements

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:
I have the same question (0)
  • Suggested answer
    Vighnesh Profile Picture
    1,942 on at

    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
    1,942 on at

    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

News and Announcements

Season of Giving Solutions is Here!

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 > Customer Service

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans