Community
Showing results for 
Search instead for 
Do you mean 
Reply

Can't update field from plugin

New Member
Posts: 1
Country: United States

Can't update field from plugin

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.

 

Thanks

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Can't update field from plugin

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.

 

BUT...

 

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