12-21-2009 11:15 PM
I am trying to update some fields when the contact record is changed and am having some trouble. If I have a value already in the field, it works fine with the following code.
currentContact.ContactFields["field alias", Act.Framework.MutableEntities.FieldNameType.Alias] = "some value";
if the field has no value, i get a system.nullreference exception.
I know that I probably need to assign some sort of object to that, but can't find how to do that? Your help would be greatly appreciated to this newbie question.
12-28-2009 01:33 PM
First you need to know alias is an optional value/label on a field descriptor and can be null/nothing until the first time the value is set. Then it can not be changed.
Alias is very usefull when creatring field from a custom plugin. The user can not change the alias in the database becuase you set the alias and you can always recall the field using the alias.
Fails when searching thru all the fields you can get an nullreference error with code like this:
For Each cField As Act.Framework.Contacts.ContactFieldDescriptor In Contacts.GetFieldDescriptors() If cField.Alias = "AliasName" Then ' Do something End If Next
In order to step over the fields with no alias values ( null references) you could do something like this:
For Each cField As Act.Framework.Contacts.ContactFieldDescriptor In Contacts.GetFieldDescriptors() If Not (cField.Alias Is Nothing) Then If cField.Alias = "AliasName" Then ' Do something End If End If Next
Hope this helps
-- Jim Durkin