how to search for a Custome using API

Hello,

I am brand new to CS2007 and was running some sample code I found in the documentation for CreateMarketingCampaign.

The first time it runs it is fine but 2nd time it blows up with Customer already exist error or such.

So my question is how do I search for a Customer by name so I can get its ID value and delete that customer.

Customer cu = marketingSystem.Customers.NewCustomer();

cu.Name ="Example Customer";

cu.Industry = ic.Name;

cu.Save(true);

marketingSystem.Customers.Search(searchclause)

I just do not understand how to create the SearchClause object to search by the customer name?

Figure that once I can find the Customer, then I can delete:

marketingSystem.Customers.Delete(intCustID);

As I mention, I have never use any version of CS before, only a couple of days of playing around with it.

Can anyone help me?

Thanks very much.

[1277 byte] By [sheir] at [2007-12-27]
# 1

If you just want to delete that customer (outside of your code), you can just hook into the appropriate web services using te Marketing Manager application. That's by far the easiest way to fix this.

The marketingSystem.Customers property is a CustomerManagers class, seen here: http://msdn.microsoft.com/library/en-us/sdkmref/html/T_Microsoft_CommerceServer_Marketing_CustomerManager.asp

There's a Search Clause factory which you would use to create that search clause object. The documentation is available here: http://msdn.microsoft.com/library/en-us/sdkmref/html/T_Microsoft_CommerceServer_SearchClauseFactory.asp

You can instantiate the factory from that Customers property, which I believe would look like:

SearchClauseFactory factory = marketingSystem.Customers.GetSearchClauseFactory();
SearchClause clause = factory.CreateClause();

I think one of the overloaded CreateClause methods will allow you to specify the clause that you want.

JosephJohnson at 2007-9-3 > top of Msdn Tech,Commerce Server,Commerce Server 2007...
# 2

Thanks for the help.

I manage to figure out the code to search for and delete the customer.

Of course I had to first search for and delete the campaign before the customer.

Here is the bit of code I came up with.

//search for and delete a customer

SearchClauseFactory scFactory = marketingSystem.Customers.GetSearchClauseFactory();

SearchClause scCust = scFactory.CreateClause(ExplicitComparisonOperator.Contains,

"Name", "Example Customer");

Microsoft.CommerceServer.SearchOptions srchOpts = new Microsoft.CommerceServer.SearchOptions();

srchOpts.NumberOfRecordsToReturn= 1;

srchOpts.PropertiesToReturn = "Id, Name, Description";//NOT SQL column names?

using (System.Data.DataSet dsCusts = marketingSystem.Customers.Search(scCust, srchOpts))

{

if (dsCusts.Tables[0].Rows.Count > 0)

{

//we found the record

custID = Convert.ToInt32(dsCusts.Tables[0].Rows[0]["Id"].ToString());

//first have to delete any campaigns attached to customer before deleting customer

SearchClauseFactory scfCam = marketingSystem.Campaigns.GetSearchClauseFactory();

SearchClause scCam = scfCam.CreateClause(ExplicitComparisonOperator.Contains,

"Name", "Example Campaign");

Microsoft.CommerceServer.SearchOptions soCamOpts = new Microsoft.CommerceServer.SearchOptions();

soCamOpts.NumberOfRecordsToReturn = 1;

soCamOpts.PropertiesToReturn = "Id, Name, Description";//NOT SQL column names?

using (System.Data.DataSet dsCam = marketingSystem.Campaigns.Search(scCam, soCamOpts))

{

if (dsCam.Tables[0].Rows.Count > 0)

{

//delete Campaigns

int camID = Convert.ToInt32(dsCam.Tables[0].Rows[0]["Id"].ToString());

marketingSystem.Campaigns.Delete(camID);

}

}//using dsCam

//now delete the customer

marketingSystem.Customers.Delete(custID);

}//if (dsCusts.Tables[0].Rows.Count > 0)

}//using dsCusts

What I found out by looking at the SQL Tables is that the record(s) are still in the table but with a "deleted" flag set to true.

sheir at 2007-9-3 > top of Msdn Tech,Commerce Server,Commerce Server 2007...