Queryentity getting null or default values for most fields (Webservice)

Dear Sirs, I'm using C# .Net and a Service Reference to run queries on CRM 7.1 API. The problem is that I get null (or default) values for most fields while running queryentity, query, etc. In the other hand, queryrecord works fine, although it's cumbersome as it forces me to specify each field name and type I want to retrieve one by one.

Please find below the code I'm using. For any reason it successfully retrieves one record including the actual primarypersonid but fails to get the values for the rest of the fields. I've checked everyone have access to the fields on CRM, they are appearing on the WSDL, the values can be seen in SQL Management Studio and they can be get by using queryrecord. Any ideas?

public static void Test()
{

HotelrezCrm crm = new HotelrezCrm();
WebServiceSoapPortClient ws = new WebServiceSoapPortClient();

crm.LogOn();

ewarebaselist CRMCompanyEmails = new ewarebaselist();
queryentityresult CRMEntityResult = ws.queryentity(crm._sessionheader, 12228, "company");
company CRMCompany = (company)CRMEntityResult.records;

crm.LogOff();
}

public void LogOn()
{
this.LogOn(DEFAULT_USER, DEFAULT_PASSWORD);
}

public void LogOn(string user, string password)
{
WebServiceSoapPort service = new WebServiceSoapPortClient();
logonRequest logonrequest = new logonRequest();
logonrequest.username = user;
logonrequest.password = password;
logonResponse logonresponse = service.logon(logonrequest);
_sessionheader = new SessionHeader();
_sessionheader.sessionId = logonresponse.result.sessionid;
_loggedon = true;
}

  • 0
    Hi Dmanta,
    You have specified that you can use queryrecord method but you need to specify each field names.
    You do not need to specify each field name while using queryrecord method, just keep that parameter as blank("") it will return all the fields.
    Regards,
    Nitesh

  • 0

    Thank you for your reply. However even not having to specify the fields initially, I'd need to loop through the records returned by queryrecord, create my own object for every record, loop through the field values returned for this record, assign the property values one by one, and keep everything up to date every time I need to get a new column field. That's why I'd like to use other methods returning "cases" objects, for example, without much coding. But after the query almost all I get are null values for the fields.

  • 0

    Unfortunately I will need to use the query method provided by the webservice.

    Did some one have a similar issue in the past (retrieving null or default values for most of the fields) while using the query method ?

    What test or inquiry would you recommend in this case, to find out the cause of the problem?

  • Hi I am experiencing the same problem, and wonder if you got the problem solved already?

  • 0

    Hi,

    Kindly try to pass 2 parameters in the queryentity method. Code should be something as below.


    Int32 CompID = ;
    queryentityresult qr = ws.queryentity(CompID, "company");
    company CRMCompany = (company)qr.records;


    Hope this helps!

    Sincerely,
    Dinesh

  • Hi Denish,

    Thanks for the response, but I already do that:

    int32 CompID = 3529;
    queryentityresult qr = ws.queryentity(SageSessionHeader, CompID, "company");
    company CRMCompany = (company)qr.records;

    If I then check the CRMCompany object all properties like CRMCompany.name, CRMCompany.website are empty or have a default value, but not the value as stored on the company in the CRM database.

    However when I access the same company using the queryrecord method i get the .name and .website contain the data as stored in the CRM database.

  • If have added the webservice as a web reference instead of as a service reference, and refactored my code.

    Now queryentity returns all data correctly.