Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Getting empty fields from CRM using Web API

(0) ShareShare
ReportReport
Posted on by 55

Hello

I have issues getting data out of CRM using Web API, my examples here are focused on the accounts entity:

Case 1: While extracting the accounts list the field 'accountnumber' comes empty for cases having values in CRM

{ "name": "DWAccountsQuery", "description": "DW query for entity account", "querytype": 0, "returnedtypecode": "account", "fetchxml": "<fetch mapping='logical' output-format='xml-platform' version='1.0' distinct='false'>
<entity name ='account'><attribute name ='accountid' /><attribute name ='accountnumber' /><attribute name ='name' /><attribute name ='statuscode' /><order attribute='accountid' /></entity></fetch>"}

request.Content = new StringContent(userQueryRep, Encoding.UTF8, "application/json");
response = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result;

no error is reported in the communication, accountid always come with value.

Case2: While knowing an specific accountid, the following query returns empty value for 'accountnumber'
accounts(b1163787-88aa-e711-8109-c4346bdc92c1)?$select=accountid,accountnumber
response = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result;

no error is reported in the communication, accountnumber comes empty.

Thank you in advance for your help.

  • Suggested answer
    Enediel Gonzalez Profile Picture
    Enediel Gonzalez 55 on at
    RE: Getting empty fields from CRM using Web API

    Thank everyone of you who helped me on this issue, deeply appreciated. The company was using jov_accountid instead of accountnumber, kind of confusing.

  • Suggested answer
    Pankaj Gogoi Profile Picture
    Pankaj Gogoi 3,177 on at
    RE: Getting empty fields from CRM using Web API

    Hi,

    Can you do an advance find on Account where accountnumber not equal to null or use the below url and  see if you get any data.

    https://yourcrm/api/data/v9.1/accounts?$filter=accountnumber ne null

    Best Regards,

    PG

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,959 Super User 2024 Season 1 on at
    RE: Getting empty fields from CRM using Web API

    Hi,

    Strange!

    Make sure you have not enabled Field Security Profile for account number field in Dynamics CRM.

    Also, The data for Account Number does exist in Dynamics.

    crmbook.powerobjects.com/.../

    Please mark my answer verified if i were helpful

  • Enediel Gonzalez Profile Picture
    Enediel Gonzalez 55 on at
    RE: Getting empty fields from CRM using Web API

    with the previous code, while debugging the application I got accountnumber=null while accountid and "name" had valid values.

  • Enediel Gonzalez Profile Picture
    Enediel Gonzalez 55 on at
    RE: Getting empty fields from CRM using Web API

    Thank you for your answer

    Let's limit the question to one, having the accountid from CRM, how to get data that currently is coming out empty like accountnumber.

    Global variables and functions
    -----------
    protected HttpClient client = null;
    JObject collection;
    public static HttpClient Client_GetHttpClient(string connectionString, string clientId, string redirectUrl, string version)
    {
    string url = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "Url");
    string username = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "Username");
    string domain = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "Domain");
    string password = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "Password");
    string authType = CRunAppConfig.GetParameterValueFromConnectionString(connectionString, "authtype");
    try
    {
    HttpMessageHandler messageHandler;

    switch (authType)
    {
    case "Office365":
    case "IFD":

    messageHandler = new OAuthMessageHandler(url, clientId, redirectUrl, username, password,
    new HttpClientHandler());
    break;
    case "AD":
    NetworkCredential credentials = new NetworkCredential(username, password, domain);
    messageHandler = new HttpClientHandler() { Credentials = credentials };
    break;
    default:
    throw new ArgumentOutOfRangeException("Valid authType values are 'Office365', 'IFD', or 'AD'.");

    }

    HttpClient httpClient = new HttpClient(messageHandler)
    {
    BaseAddress = new Uri(string.Format("{0}/api/data/{1}/", url, version)),

    Timeout = new TimeSpan(0, 2, 0) //2 minutes
    };

    return httpClient;
    }
    catch (Exception)
    {

    throw;
    }
    }

    -----------

    From CRM I was able to extract the name and accountid for all the accounts, in the following code I need to extract the accountnumber for the accountid b1163787-93aa-e711-8109-c4346bdc92c1, right now is coming out empty when accountid and "name" come out with their proper values.

    string[] AccountEntityAdditionalProperties = {
    "accountid"
    ,"accountnumber"
    ,"name"
    };

    client = Client_GetHttpClient(
    APICRMConnectionString,
    AzureClientID,
    AzureRedirectUrl,
    "v9.1");

    string url = "accounts(b1163787-93aa-e711-8109-c4346bdc92c1)?$select=accountid,accountnumber,name";

    response = client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result;
    JObject collection;
    if (!response.IsSuccessStatusCode)
    return false;
    collection = JObject.Parse(response.Content.ReadAsStringAsync().Result);
    JArray singleton = new JArray(collection);

    foreach (JObject entity in singleton)
    {


    string PropertyValue = "";
    foreach (string PropertyName in AccountEntityAdditionalProperties)
    {
    try
    {

    string formattedProperty = PropertyName + "@OData.Community.Display.V1.FormattedValue";
    PropertyValue = "";

    if (null != entity[formattedProperty])
    PropertyValue = entity[formattedProperty].ToString();
    else
    if (null != entity[PropertyName])
    PropertyValue = entity[PropertyName].ToString();

    }
    catch (Exception ex)
    {

    }
    }

  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,331 on at
    RE: Getting empty fields from CRM using Web API

    Hi Partner,

    Please check the following points.

    1.Test the web api through web url directly to check if the response contains accountnumber.

    Specific account.

    2465.pastedimage1601015326214v1.png

    Multiple account.

    1263.pastedimage1601015381352v2.png

    2.Debug your code in VS step by step to make sure if the original response is null or caused by the coding(UTF-8).

    You could also share your complete code about the query function so that we could debug for you.

    Regards,

    Leo

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,703 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,433 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans