Saving to a Dictionary Item

Vote:
 

Hello,

I've created a new Business Object in Episerver Commerce 7.5 under the Contact List section. I've set it up as a multi value list and preset all the values. I need to set the value(s) of this property from the code beind. What do you need to pass through to get this to save successfully?

 

Thanks

Paul

#84677
Apr 04, 2014 11:16
Vote:
 

Did you find a soultion? I've been searching in the SDK and sample sites, but I can't find any code examples.

#86321
May 19, 2014 12:26
Vote:
 

Hi,

You can try to update the CustomerContact by using this:

CustomerContact customer = CustomerContext.Current.GetContactById(YOUR_CONTACT_GUID);

customer.Properties["YOUR_PROPERTY_NAME"].Value = NEW_INT_ARRAY;

// then save it

customer.SaveChanges();

Assume that NEW_INT_ARRAY is the int[] that contains the property value.

Hope this could help.

Ton Nguyen.

#86356
May 20, 2014 9:28
Vote:
 

I am trying to do this while creating users. I create users in an import-users-from-an-old-system-custom-job. The code runs fine until I add the code for setting dictionary list values.
The code in your example does not work Ton, customerContact.Properties["PropertyName"] is null, so it crashes. I have "Dictionary items" with the "Single value" and "Multi value". The code does not crash when I do customerContact["PropertyName"] = 1; (Using an int array crashes the code for single value items) I am able to run customerContact.SaveChanges(), but it does not store the values. When I look at the user in the Commerce Manager, it says "No value" for the property.

I have tried several different variations for the multi value field as well. In the examples below, there are 4 defined values, and it keep crashing on SaveChanges()
customerContact["MultiSelectProperty"] = new int[] {1};
customerContact["MultiSelectProperty"] = new int[] {0, 0, 1, 0};
customerContact["MultiSelectProperty"] = new string[] {"selcted_value"};
If I change the code to the following, it does not crash, but it does not store the information correctly.
customerContact.Properties.Add("MultiSelectProperty", 1);
customerContact.Properties.Add("MultiSelectProperty", new int[] {1});

Lets say you have a single value dictionary item with the options "Male" and "Female". How would your code look like to save "Male" for a customer contact?
And lets say you have a multi value dictionary item with options like "Blue", "Yellow", "Green", "Black". How would your code look like to save "Blue" and "Green" for a customer contact?

I would REALLY appreciate it if you can give some examples :)

#86394
May 20, 2014 17:09
Vote:
 

As far as I understand, you are setting this property value while running a schedule job, right? Then it might have been the context problem.

Could you try to verify if that example work in a Web context? I would appreciate if you can find and give me the crash error detail.

#86526
May 23, 2014 7:57
Vote:
 

I finally got it working :) Here is a blog post I wrote with code examples:

http://www.epinova.no/blog/Lars-Oyvind-Bodahl/dates/2014/5/saving-dictionary-items-on-a-commerce-contact/

#86547
May 23, 2014 12:24
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.