cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4643
Views
1
Helpful
16
Replies

Context Service Search

Jon4321
Level 4
Level 4

Hi,

I've been unable to get search working in Context Services. I had it working two months ago with the version 4 jar files. Started the same project up four days ago and was unable to search for a customer. Downloaded the version 7 files from the site and got them working in the project same problem. Has anyone else encountered this issue?

16 Replies 16

Jonathan, I see that you are not creating a customer prior to trying to look up. It is possible that the customer that you are trying to lookup might not exist in the same workgroup or was created prior to KMS changes or was wiped out when Context Service deleted all data around the time when KMS changes were implemented.

Let's start fresh:

Can you please add following:

1) import com.sun.jersey.api.client.ClientResponse;

2)

public static void createCustomer() {

   // Create a new Customer
   Map<String, Object> custData = new TreeMap<String, Object>(){{

  put("Context_Work_Email", "michael.littlefoot@cc.com");

  put("Context_Work_Phone", "407-775-5938");

  put("Context_First_Name", "Michael");

  put("Context_Last_Name", "Littlefoot");

  put("Context_Street_Address_1", "175 Cedar Lane");

  put("Context_City", "New Orleans");

  put("Context_State", "LA");

  put("Context_Country", "US");

  put("Context_ZIP", "70113");

  }};

  Customer customer = new Customer(DataElementUtils.convertDataMapToSet(custData));

  customer.setFieldsets(new ArrayList<String>(Collections.singleton("cisco.base.customer")));

  com.cisco.thunderhead.client.ClientResponse customerResp1 = contextServiceClient.create(customer);

   final String customerId = SDKUtils.getIdFromResponse(customerResp1);

  String customerLoc = customerResp1.getLocation().toString();

  System.out.println("Customer Created. ID: " + customerId + " Location: " + customerLoc);

}

3)

public static void searchCustomer() {

   // Lookup Customers on Key/Value Pairs of PII Fields
   SearchParameters customerLookup = new SearchParameters(){{

  add("Context_First_Name", "Michael");

  add("Context_Country", "US");

  }};

  List<Customer> cusLookup = contextServiceClient.search(Customer.class, customerLookup, AND);

  System.out.println("Customers associated with Lookup Criteria " + customerId + ':');

   for(Customer cust : cusLookup ) {

   // print the Customer Id(s) matching the Lookup criteria
   System.out.println("Customer ID: " + cust.getId().toString());

  }

}

4)

Then in your code, use createCustomer() first then searchCustomer()

5) You can remove the createCustomer() for all subsequent run since the customer will be present in database that you would try to lookup.

Please let me know if this helped!

Thank you

Ankit Parikh

Hi Ankit,

Just tried creating a new customer as it worked I can search for this customer. I also tried searching for the customer by phone number and that worked as well.

That's seems to solved the issue thanks for your help.

Jonathan