Community
Showing results for 
Search instead for 
Do you mean 
Reply

Finding and editing field properties

Tuned Listener
Posts: 8
Country: Australia

Finding and editing field properties

My questions apply to the construction of a custom control, using VB. Currently based on Act!12, the control's code is filled with references to MutableEntityFiedDescriptors, and I have no trouble getting collections of these, and getting individual ones, according to various criteria. However I have a need to do a couple of (possibly unusual) things, and cannot work out how.

 

Q1: Is it possible to determine whether a particular field is bound to a control, other than iterating through all the controls in the layout looking for a connection?

Q2: Can someone point me to a code sample for changing a field's property - for instance the size of a character field?

 

In hope,

David

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Finding and editing field properties

David

 

1) If ACT uses a BindingSource component you could use it.  Otherwise just walk the controls.

 

 2)  Here are some examples for different types of ACTDataTypes

 

'//Get the field

 Dim field As FieldDescriptor = New Act.Framework.Database.FieldDescriptor(sName, sAlias, EntityDescriptor, FieldType)

 

'//Set some attributes like length

field.Attributes(Act.Framework.Database.FieldProperty.Length) = New Act.Framework.Database.LengthAttribute(iLength)

 

 

'// Decimal precision

field.Attributes(FieldProperty.DecimalPrecision) = New DecimalPrecisionAttribute(iLeftPrecision, iRightPrecision)

 

 

'// Default value for logicals

field.Attributes(FieldProperty.DefaultValue) = New DefaultValueAttribute(True)

 

'// Set Triggers

field.Attributes(FieldProperty.ChangeTrigger) = New ChangeAttribute(TriggerType.None, Nothing)
field.Attributes(FieldProperty.FocusTrigger) = New FocusAttribute(TriggerType.None, Nothing)field.Attributes(FieldProperty.LostFocusTrigger) = New LostFocusAttribute(TriggerType.None, Nothing)

 

''// Set a picklist

field.Attributes(FieldProperty.PickList) = New PickListAttribute(pickList, True, False, True, False)

 

 

Hope this helps

-- Jim Durkin

Tuned Listener
Posts: 8
Country: Australia

Re: Finding and editing field properties

Hi Jim.

Thanks very much. On my first question, I can't find any property or attribute of any type of field descriptor that indicates even that the field has a bound control, let alone which control is bound to it! I must be missing something. 

On Q2, your suggestion is fine, but it still leaves a problem. 'field' needs to be saved, otherwise the changes have no effect. And when I try to do that, the save fails with the error message 'The descriptor name <sName> is already in use and cannot be applied.'

My 'save' code is:-

 

ActFM.Database.LockDatabase(Act.Framework.DatabaseLockReason.SchemaChanges)
ActFM.Fields.Save(field)                           

ActFM.Database.UnlockDatabase()

 

Any ideas?

I appreciate your help. Cheers

David

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Finding and editing field properties

David,

Q1) Can't you just iterate thru the controls then check the dataBinding. This is sudo code....

For Each Ctrl As Control In cControls.Controls

  If TypeOf Ctrl Is TextBox Then

      If Ctrl.DataBindings != nothing

       '// Do something

    End If

  End If

Next

 

Q2) 

Yep, that example code was to create a new field. To save an existing field you can use this example but its for custom entity field and I never tested it with top level entities ( Contacts, Companies, groups and/or opps)

 

ACTFramework.Fields.Save(Me.FieldDescriptor)

 

Also, if you are providing an user interface that allows them to change the field type you need to check out the Field converter...

 

ACTFramework.Fields.Convert(Me.FieldDescriptor, Act.Framework.Database.FieldDataType.Character)

 

Hope this helps

-- Jim Durkin

Tuned Listener
Posts: 8
Country: Australia

Re: Finding and editing field properties

Jim,

Q1 - Yes, iteration through the controls works, but it takes forever. The situation is that I need to produce an array of all fields that are not currently bound. This is in a control designer, by the way, and the problem arises because, in Act 12, the field picker dialog used for selecting a field to bind to the control being designed, does not work. (Or, at least, I can't get it to work!!!! - the old field picker has been replaced with a Mutalble Entity equivalent, and it presents no  fields. (See my post dated 22 Jan. - zero responses.) So - naughty, I know - I'm loading its list box with the fields. This works, but I can't find an Act thingy that gets just the unbound fields, so I have to remove these from the array loaded with the total field collection. That can mean 30-100 controls being checked for binding to each one of 80-100+ fields, and that takes too long. (It amazes me that after binding, the binding is not evident from both sides if the bind. Still, we are dealing with Act!)

Q2 - still in the control designer - after selecting a field in the field picker (it's a character type), all I want to do is increase its length if it is below a certain limit.I could just tell the user (via a message box) to edit the field, but that's messy and unreliable, because it would have to be released from the control before he could do that. then he would have to re-select it, to get it bound back to the control being designed. 

Thanks for your suggestion re. saving, but it doesn't work, because the Error Guardian says that the value to be saved is of type MutableEntity.MutableEntityFieldDescriptor, and can't be converted to a Database.FieldDescriptor type. Being in a control designer, Me is the designer, not the control, so I have to substitute as follows:-

ActFM.fields.Save( CType(Me.Control, <classname of the control>).FieldDescriptor)

Thanks again, and any further thoughts you may have would be appreciated.

David