SBX - Search With Button

SBX - Forum Post Title

IOrganizationService.RetrieveMultiple

Microsoft Dynamics CRM Forum

Arturo Nava asked a question on 16 May 2019 4:12 PM

Question Status

Verified
Hello, help to make visual project studio C #, I need to export records of my entity Product.

Subsequently those records serialize them to XML.

I need an example.

This method is correct: IOrganizationService.RetrieveMultiple ???

I appreciate the support.

regards!
Reply
Ravi Kashyap responded on 16 May 2019 6:33 PM
Suggested Answer

Hi,

RetrieveMultiple message will return the collection of entity objects. Once retrieved you can use below sample to serielze it accordingly-

docs.microsoft.com/.../sample-serialize-deserialize-entity-instance

Hope this helps.

Reply
Arturo Nava responded on 16 May 2019 7:39 PM

Hi, thanks for the serialize example, I already have it ...

The problem I have is to connect to my organization and extract the products from the Product entity.

help me

Reply
N.A.R.A responded on 17 May 2019 1:57 AM

This is the example

The result are entity collection, you can just convert to list of entity

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;



//This is how to connect

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

Uri crmOrganizationUri = new Uri("yourorganizationurl");
var credentials = new ClientCredentials()
{
UserName = { UserName = "yourusername", Password = "yourpassword" }
};
var serviceProxy = new OrganizationServiceProxy(crmOrganizationUri, null, credentials, null);
serviceProxy.EnableProxyTypes();
if (impersonateGuid != default(Guid))
{
serviceProxy.CallerId = impersonateGuid;
}



//This is how to query

QueryExpression productQe = new QueryExpression()
{
EntityName = "product",
ColumnSet = new ColumnSet(true),
Criteria = new FilterExpression()
{
//if you want add condition
Conditions = { new ConditionExpression("name", ConditionOperator.Equal, "Arturo Nava") }
}
};
EntityCollection productEc = serviceProxy.RetrieveMultiple(productQe);


Good Luck 

Reply
Suggested Answer

Hi

The following query will help you to retrieve products

// Instantiate QueryExpression QEproduct

var QEproduct = new QueryExpression("product");

// Add columns to QEproduct.ColumnSet

QEproduct.ColumnSet.AddColumns("name", "productid", "productnumber", "description", "statecode", "productstructure");

QEproduct.AddOrder("productnumber", OrderType.Ascending);

CrmService.RetrieveMultiple(QEproduct );

If you are not familiar with building query using query expression, you can use the XrmToolBox Fetch XML builder as shown below

01. Build your query in advance find and download the FETCH

02. Paste your FETCH and Convert to Query Expression C# code as shown below

Once you got the results, you can serialise or de-serialise as described in the link below

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/org-service/sample-serialize-deserialize-entity-instance

Reply
Arturo Nava responded on 17 May 2019 4:59 PM

Hello N.A.R.A, I appreciate your help and time, I tell you to do what you send, ask, why does not show the method RetrieveMultiple ???

What is the error?

Regards!

Reply
Arturo Nava responded on 17 May 2019 6:06 PM

Hello N.A.R.A, review and the RetrieveMultiple method, it is shown with _service.

not with serviceProxy

Regards!

Reply
Arturo Nava responded on 18 May 2019 11:52 AM

I appreciate your support Ravi, to be serialized.

Do you have an example for RetriveMultiple ??

Thanks for your support.

Reply
Arturo Nava responded on 18 May 2019 12:43 PM

Hello Kokulan,

Thanks for answering ,,, Question..What is the difference between IOrganizationService.RetrieveMultiple vs. CrmService.RetrieveMultiple ????

Is the same??

I appreciate your support.

regards!

Reply
Verified Answer

Hi Arturo

CrmService in my example is just the variable name for OrganizationService, yes you are right its referring to the same IOrganizationService.RetrieveMultiple.

Reply
Arturo Nava responded on 19 May 2019 5:31 PM

Kokulan, I understand, I appreciate your help, thank you!

Reply
Verified Answer

Hi Arturo

CrmService in my example is just the variable name for OrganizationService, yes you are right its referring to the same IOrganizationService.RetrieveMultiple.

Reply
Ravi Kashyap responded on 16 May 2019 6:33 PM
Suggested Answer

Hi,

RetrieveMultiple message will return the collection of entity objects. Once retrieved you can use below sample to serielze it accordingly-

docs.microsoft.com/.../sample-serialize-deserialize-entity-instance

Hope this helps.

Reply
Suggested Answer

Hi

The following query will help you to retrieve products

// Instantiate QueryExpression QEproduct

var QEproduct = new QueryExpression("product");

// Add columns to QEproduct.ColumnSet

QEproduct.ColumnSet.AddColumns("name", "productid", "productnumber", "description", "statecode", "productstructure");

QEproduct.AddOrder("productnumber", OrderType.Ascending);

CrmService.RetrieveMultiple(QEproduct );

If you are not familiar with building query using query expression, you can use the XrmToolBox Fetch XML builder as shown below

01. Build your query in advance find and download the FETCH

02. Paste your FETCH and Convert to Query Expression C# code as shown below

Once you got the results, you can serialise or de-serialise as described in the link below

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/org-service/sample-serialize-deserialize-entity-instance

Reply

SBX - Two Col Forum

SBX - Migrated JS