Welcome to MSDN Blogs Sign in | Join | Help
Sample Adapter Search Clause Messages

There have been a couple of questions about our Commerce Server orders and profiles Biztalk adapter query format and how to generate such a format.  I thought I would show a very simplistic example of how one would go about generating a query message for orders/profiles Adapter. 

First off, the adapter uses the Commerce Server search clause as the basis of it's query.  This search clause is the same clause that can be used to search for orders or profiles from any custom business application.

This example shows how to generate a query that will return all UserObject profiles where the last name is equal to 'faulkner'. 

string ProfileQueryXML= "<CommerceServerProfilesQuery ProfileType=\"UserObject\" ReturnKeysOnly=\"True\">[SearchClause]</CommerceServerProfilesQuery>";

ProfilesServiceAgent agent = new ProfilesServiceAgent("http://localhost/profileswebservice/profileswebservice.asmx");

ProfileManagementContext ctxt = ProfileManagementContext.Create(agent);

DataSet searchableProperties = ctxt.GetSearchableEntities();

SearchClauseFactory factory = ctxt.GetSearchClauseFactory(searchableProperties, "UserObject");

SearchClause clause = factory.CreateClause(ExplicitComparisonOperator.Equal, "last_name", "faulkner");

string query = ProfileQueryXML.Replace("[SearchClause]", clause.ToXmlElement().OuterXml);

XmlDocument profileQueryDoc = new XmlDocument();

profileQueryDoc.LoadXml(query);

profileQueryDoc.Save(@"C:\ProfilesQuery.xml");

For orders, it's the same game.  Here is an example of how to generate a query that will return all PurchaseOrders where status is 'Submitted'

string OrderQueryXML = "<CommerceServerOrdersQuery>[SearchClause]</CommerceServerOrdersQuery>";

OrderServiceAgent orderAgent = new OrderServiceAgent("http://localhost/orderswebservice/orderswebservice.asmx");

OrderManagementContext orderMgtContext = OrderManagementContext.Create(orderAgent);

PurchaseOrderManager poMgr = orderMgtContext.PurchaseOrderManager;

SearchClauseFactory factory = poMgr.GetSearchClauseFactory(poMgr.GetSearchableProperties("en-US"), "PurchaseOrder");

SearchClause clause = factory.CreateClause(ExplicitComparisonOperator.Equal, "Status", "Submitted");

string query = OrderQueryXML.Replace("[SearchClause]", clause.ToXmlElement().OuterXml);

XmlDocument xdoc = new XmlDocument();

xdoc.LoadXml(query);

xdoc.Save(@"C:\OrdersQuery.xml");

When all is said and done, here is what the queries will look like:

Profiles:
<CommerceServerProfilesQuery ProfileType="UserObject" ReturnKeysOnly="True">
  <CLAUSE OPER="equal" xmlns="http://schemas.microsoft.com/CommerceServer/2004/02/Expressions">
    <PROPERTY ID="last_name" MULTIVAL="false" TYPE="String" />
    <IMMED-VAL TYPE="String">
      <VALUE>faulkner</VALUE>
    </IMMED-VAL>
  </CLAUSE>
</CommerceServerProfilesQuery>

Orders:
<CommerceServerOrdersQuery>
  <CLAUSE OPER="equal" xmlns="http://schemas.microsoft.com/CommerceServer/2004/02/Expressions">
    <PROPERTY ID="PurchaseOrder.Status" MULTIVAL="false" TYPE="String" />
    <IMMED-VAL TYPE="String">
      <VALUE>Submitted</VALUE>
    </IMMED-VAL>
  </CLAUSE>
</CommerceServerOrdersQuery>

I hope this helps!!!

 

 

Posted: Wednesday, June 14, 2006 9:07 PM by akfaulkner

Comments

Ravi Kiran.J said:

ctxt.GetSearchableEntities() This invocation doesnt seem to work consistently. I see an exception in every 7 to 8 times i invoke this method either thru code or thru web browser.

The exception reads as below...
"A DataTable UserObject alredy belongs to the DataSet" Please let me know if there is a work around asap. It will be of great help to me.

Thanks in advance,
Ravi Kiran.J
# July 30, 2006 3:46 AM

akfaulkner said:

Ravi,

Can you paste the code that you are using to get the context?  Also, is it 1 out of 8 times that the exception occurs and is it consistent?

Let me know

Alan
# August 3, 2006 2:48 AM

André said:

Is there another way to search profiles without using Web Services and with Clauses?
# August 15, 2006 7:30 PM

Ravi Kiran.J said:

Hi Alan,

Its Ravi here again. Nice to see ur response.
I will tell you the scenario. I have written a class called ProfileManger which is the datalayer for my project. This is a wrapper class for the Commerce Server APIs. The Context object is created in the Constructor. Here is the sample code.

public class ProfileManager
{
ProfilesServiceAgent pa = null;
ProfilesManagementContext pm = null;

ProfileManager()
{
 ProfilesServiceAgent pa = new ProfilesServiceAgent("http://localhost/ProfilesWebService/ProfilesWebService.asmx");

 ProfilesManagementContext pm =  ProfilesManagementContext.Create(pa);
}

I have written few methods in this class to implement a wrapper over the existing Commerce Server SearchClause functionality.

public SearchClause GetSearchClause(DataTable searchClauses, string profileType)
{

/*It is here that the exception is being raised. Almost for every 2nd or 3rd attempt it is behaving like this. Moreover, i have seen this behaviour when invoking the webservice in the browser and Clicking on the Web Method GetSearchableEntities. Try invoking the method for 5 to 6 times and will get an exception saying "The table XYZ already belongs to the DataSet".*/

DataSet searchableProperties = ctxt.GetSearchableEntities();

SearchClauseFactory factory =  ctxt.GetSearchClauseFactory(searchableProperties, profileType);

}

public dataset GetSearchResults(searchOptions, searchClause, profileType)
{
...  
}
} // End of class
Whats ur guess Alan?


Thanks & Regards,
rAvi.
# August 16, 2006 10:22 PM

akfaulkner said:

Andre,

No - You have to go through the Web Service to perform Profile Search using SearchClause.  An alternative would be to go through ADO.NET.

Hope this helps.

Alan
# August 17, 2006 6:34 PM

André Nobre said:

Thanks Alan,
but going through ADO.NET requires and extra effort and a kind of doing something that is alredy done. I saw the BulkQuery class and some others, I´ll see if it can help me in something.

Thanks again.
# August 21, 2006 8:58 AM

André Nobre said:

Alan, I´m talking about this with Nihit, but I got no answer by now. The problem that generated this questions is this:

"Hi Nihit,
Our problem isn´t about custom properties, but in custom Profiles. We created a custom profile "OptIn", and the GetSearchableEntities() does not returns this new profile as searchable one. "

This have been a huge problem, since we created a lot of custom profiles (and custom properties).
# August 21, 2006 9:11 AM

akfaulkner said:

Andre,

Did you create a new scope for that profile?  You will need to create a new scope in the Profile Authorization Store via Azman.msc.

Hope this helps,

Alan
# August 21, 2006 11:59 AM

André Nobre said:

Alan,
I did this, and it worked, thanks. I´m only a little disappointed about the documentation (just on this, because it´s very complete). This "create a new scope" was documented somewhere? Since friday I was looking for the solution for this problem, and I just solve this with your help.

If this is documented, let me know.

Thanks again.

André
# August 21, 2006 4:17 PM

Dom said:

Hi,

Do you have your project to download? I do no thave the objects SearchClauseFactory, searchClause, ProfilesServiceAgent, ProfileManagementContext etc. Unless these are from the commerce server 2007 SDK?

Thanks

Dom

# October 24, 2006 9:37 AM

akfaulkner said:

Hey Dom,

Those classes are actually part of the Commerce Server 2007 API (not in SDK).  You can find those classes by looking in the .NET Reference documentation for CS 2007.

Hope this helps!

Alan

# October 25, 2006 2:35 AM

Dom Melino said:

Thanks found the correct assemblies

# October 25, 2006 5:11 AM

Dom Melino said:

Hello Again,

Thanks for the info about how to get the sample working. Do you have a sample of the inventory adapter? I would like to get an example of the CommerceServerInventoryQuery SearchClause XML and how to use it like what you have got on this page. I would like to query the catalog and also update the catalog with the catalogwebservice.asmx.

Thanks

# November 27, 2006 10:46 AM

dinh said:

Hi,

I am trying to search the records of Organization profile by using the

ProfileManagementContext class. I'm getting the error when i'm calling the

following code,

// Build dataset of searchable entities for a profile.

DataSet searchableEntities  = profile.GetSearchableEntities();

// Build search clause for the Organization.

SearchClauseFactory factory =

profile.GetSearchClauseFactory(searchableEntities, "Organization");

I'm getting the error message as follows,

System.ArgumentException: DataSet is missing the 'Organization' table.

Parameter name: searchableEntities

I checked the Profile Authorization Store using azman.  It seems to have the correct permission as stated in the Starter Site Installation Guide.  Am I missing something?

Any help would be great.  Thanks in advance!

# December 27, 2006 5:11 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker