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]
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 customerSearchClauseFactory 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 recordcustID =
Convert.ToInt32(dsCusts.Tables[0].Rows[0]["Id"].ToString());//first have to delete any campaigns attached to customer before deleting customerSearchClauseFactory 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 Campaignsint camID = Convert.ToInt32(dsCam.Tables[0].Rows[0]["Id"].ToString());marketingSystem.Campaigns.Delete(camID);
}
}
//using dsCam//now delete the customermarketingSystem.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.