How to retrieve data from entity (table) in SageCRM?

by Raju Maharjan 1. December 2010 22:01

With queryrecord method you will be able to retrieve the list of the records from entity. It is pretty simple to build your own SQL query while dealing with the queryrecordRequest  object of your web service. All you need to do is set fieldlist, entityname, queryString ,orderby and SessionHeader  properties exposed in the object and you will build your custom query to retrieve records for the entity.

SessionHeader crmSessionHeader = new SessionHeader();

WebServiceSoapPort CRMService = new WebServiceSoapPortClient();

void GetAllRecordsInEntity()

        {

            string listofFields = "";// blank will return all the fields or you can set the comma separated column names;

            string whereClause = "";//" blank for no condition or set as "type='user'" for condition

            string entityName = "Users";// Define entity name (which is a database table) here 

            string orderBy = "";// set  order by with desired column

 

            queryrecordResponse objQueryRecordResponse = new queryrecordResponse();

            queryrecordRequest objQueryRecordRequest = new queryrecordRequest();

            objQueryRecordRequest.fieldlist = listofFields;

            objQueryRecordRequest.entityname = entityName;

            objQueryRecordRequest.queryString = whereClause;

            objQueryRecordRequest.orderby = orderBy;

            objQueryRecordRequest.SessionHeader = crmSessionHeader;            

            objQueryRecordResponse = CRMService.queryrecord(objQueryRecordRequest);

            queryrecordresult myQueryRecordResult = objQueryRecordResponse.result;            

            crmrecord[] myRecordList = myQueryRecordResult.records;            

            for (int i= 0; i< myRecordList.Length; i++)

            {

                recordfield[] myFieldList = myRecordList[i].records;

                for (int j= 0; j< myFieldList.Length; j++)

                {

                    recordfield myField = (recordfield)myFieldList[j];

                   //use myField.name for column name and  myField.value for value field

                }

            }

        }

 

Domain Registration, Web Hosting and Web Services 
Domain Registration, Web Hosting and Reseller Web Hosting 
Start Web Hosting from just $2.5/Month

Tags: , , ,

SageCRM

Comments

Add comment


() (Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading




Sapnep IT Solution

We Provide IT solutions and services to deliver a unique blend of real-business experience with a strong engineering, international project delivery. We are a software development  firm.