Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

How to add custom property in organization addresses?

Vote:
 

How to add custom property in organization addresses?Any one please help me out?

i want add one new property in addresses.

#184449
Edited, Oct 27, 2017 11:13
Vote:
 

Please refer here http://webhelp.episerver.com/latest/commerce/system-administration/order-meta-classes-fields.htm.  You will want to create a new meta field and then associate that field with OrderAddressEx meta class

#184482
Oct 27, 2017 20:19
Vote:
 

Thanks mark.

I am adding the customer management->organization -> address via code.

How to assign the values to that custom properties and retrive that also.please help me out.

I am Adding an Customer addresses like below,

Organization org = CustomerContext.Current.GetOrganizationById(orgkey);
var address= CustomerAddress.CreateInstance();
address.AddressType = CustomerAddressTypeEnum.Shipping;
.

.
address.RegionCode = wlcOrganizationAddress.AccountId;
address.OrganizationId = org.PrimaryKeyId;
BusinessManager.Create(address);

#184489
Edited, Oct 28, 2017 11:56
Vote:
 
address["FieldName"] = value;

var value = (string)address["FieldName"]

var value = address.GetStringValue("FieldName");
#184619
Edited, Oct 31, 2017 17:29
Vote:
 

Thank you Mark,

Already i tried this code.If i use this "address["FieldName"] = value;" the custom property value is added into Extended properties but i dont think the value saved into database.If i tried to retrive the value is empty only.

#184626
Nov 01, 2017 8:45
Vote:
 

Have you saved the customer contact after you added it?

#184654
Nov 01, 2017 13:53
Vote:
 

Hi Erik,

I have saved using this funtion "BusinessManager.Create(address);" all the other default properties are saved only the custom properties not saved.

#184675
Nov 02, 2017 8:24
Vote:
 

Can you check if DefaultMetaObjectFactory.CanCreate returns true for your metaclass?

#184717
Nov 02, 2017 13:45
Vote:
 

Also do try and create it first, then add you custom properties and save it again.

Default properties isn't stored in the same array and it is even stored on a base class so it isn't the same code that handles them.

#184724
Nov 02, 2017 14:12
Vote:
 

Hi Erik,

Thank you.

I made one mistake in adding meta field for address.so now i added meta field using code and saved my custom property like above code (#184489).

private void SetupMetaField()
{
MetaClassManager metaModel = DataContext.Current.MetaModel;
foreach (MetaClass metaclasses in metaModel.MetaClasses)
{
if (metaclasses.Name == "Address")
{
string fieldName = "meta field name";
if (metaclasses.Fields[fieldName] == null)
{
AttributeCollection attr = new AttributeCollection();
MetaField newMetafield = metaclasses.CreateMetaField(
fieldName,
"meta field name",
MetaFieldType.Text,
true,
string.Empty,
attr);
}
break;
}
}
}

if there any way to add meta field to customer management address using commerce backend.

please inform me.

#184804
Nov 04, 2017 11:24
Vote:
 

commerce backend as in the commerce manager administration UI?

Commerce->Commerce Manager->Administration->System settings->Business Foundation

The "Address" object contains the definitions for all those meta fields, if it can be done it is there.

On a side note your above code is more complex than needed, to retrieve and create a field on address you can do something similar to this:

var metaClass = DataContext.Current.GetMetaClass("Address");

using (var myMetaBuilder = new MetaFieldBuilder(metaClass))
{
    myMetaBuilder.MetaClass.AccessLevel = AccessLevel.Customization;
    myMetaBuilder.CreateText("meta field name",
                             "meta field friendly name",
                             true,
                             256,
                             false);
    myMetaBuilder.SaveChanges();
}
#184873
Edited, Nov 06, 2017 15:57
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.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.