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!!!