Community
Showing results for 
Search instead for 
Do you mean 
Reply

Change a Custom Sub-Entity field DisplayName?

Copper Contributor
Posts: 123
Country: Canada

Change a Custom Sub-Entity field DisplayName?

Hey everyone, I'm fairly new with the SDK but had a quick question.

How does one go about changing the DisplayName of a field residing in a Custom Sub-Entity in C#?

I'm sure it is completely obvious but for some reason this is what is giving me a hard time.

Thanks again!

-Eric

Employee
Posts: 1,163
Country: USA

Re: Change a Custom Sub-Entity field DisplayName?

Changing the property for a custom field is similar to how you'd do it for any other field, it will change slightly however depending on what the parent entity is. 

 

MutableEntityFieldDescriptor mefd = _ActApp.ActFramework.Opportunities.GetMutableEntityFieldDescriptor(realFieldName, true);

 

realFieldName above is the column name of the field descriptor, alternatively, if you only need to get the value you can also use the OLEDB provider, an example of doing this can be found here

 

Hope that helps, if you have any more questions don't hesitate to ask.

Matthew Wood
Act! SDK Support
Community Moderator
Copper Contributor
Posts: 123
Country: Canada

Re: Change a Custom Sub-Entity field DisplayName?

Ok thanks alot Matt I will try it again keeping that in mind.  I think maybe I wasn't using the realFieldName and that was my problem.

Your input is much appreciated!  Just about everytime I get stuck on something it is one of your posts in the forum that helps me out.  Thank you!

-Eric

Copper Contributor
Posts: 123
Country: Canada

Re: Change a Custom Sub-Entity field DisplayName?

I'm still having trouble and it is probably just that I am missing something very fundamental.

 

I have my Custom-Sub Entity created and am able to set values on the fields and I can get the DisplayName of the field as a string But I can't change the DisplayName of the field, I must be missing a critical / logical step.

I display the DisplayName property of the field by using the following code:



CustomEntityDescriptor refundDescriptor = actApplication.ActFramework.CustomEntities.GetCustomEntityDescriptor("REFUND");

 

CustomEntityManager<Refund> manager2 = actApplication.ActFramework.CustomEntities.GetSubEntityManager<Refund>(refundDescriptor);

Framework.CustomEntities.CustomEntityFieldDescriptor descr = manager2.GetCustomEntityFieldDescriptor("CUST_REFUND.CUST_REFUND_Adjustments_105649501", true);

MessageBox.Show(descr.DisplayName.ToString());



I can change attributes on the field but for some reason I can't figure out how to change the DisplayName property and it is driving me nutts!  I realize it is probably something very simple that I just haven't learned yet.  Any help or a point in the right direction would be much appreciated.

-Eric

Copper Contributor
Posts: 123
Country: Canada

Re: Change a Custom Sub-Entity field DisplayName?

Or can I just save a field descriptor overtop of the one already created?

field = new FieldDescriptor("Adjustments", "REFUND_Adjustments", refundDescriptor, FieldDataType.Currency);
this.actApplication.ActFramework.Fields.Save(field);

Basically that is where I get confused I guess...

Employee
Posts: 1,163
Country: USA

Re: Change a Custom Sub-Entity field DisplayName?

i was under the impression that DisplayName is a public property, however it isn't for the MutableEntityFieldDescriptor class; it's read only, same for the DisplayName property under the CustomEntityDescriptor class. 

 

I'm not 100% positive why this property is read only in these two circumstances, but I assume it has to do with the way in which fields are named in the reporting provider. 

Matthew Wood
Act! SDK Support
Community Moderator
Copper Contributor
Posts: 123
Country: Canada

Re: Change a Custom Sub-Entity field DisplayName?

Ok that is what I thought as I only saw { get } in the definition.  But I guess I figured there was just another way of going about it as I am still very much a newbie.

I just wanted to know if it was possible and thought I was missing something very obvious.  So I guess I would have to create a new field with the properties that I want and then copy the data over?

Otherwise I will just have to be darn sure about the field DisplayNames before I create them in the Sub-Entity.

Copper Contributor
Posts: 123
Country: Canada

Re: Change a Custom Sub-Entity field DisplayName?

Thanks for your promt response Matt and for looking into it for me.

-Eric

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Change a Custom Sub-Entity field DisplayName?

Try using the NAME property

 

MyFieldDescriptor.Name = Durkin.Common.Utilities.Strings.StripInvalidCharacters(Me.txtFieldName.Text, "")

 

Below is the procedure we use to allow the users to make changes to a field descriptor. You will need to build your own UI/form. Hope it helps...

 

-- Jim Durkin

 

 

Private Function SaveFieldChanges() As Boolean

        Try
            If Me.FieldDescriptor Is Nothing Then
                '----------------------------------------------------
                ' Strip out any invalid characters
                ' “~!@#$%^&*()+-`=,./\|{}?;:><“ 
                '----------------------------------------------------
                Dim sFieldName As String = Durkin.Common.Utilities.Strings.StripInvalidCharacters(Me.txtFieldName.Text, "")

                If Me.EntityDescriptor Is Nothing Then
                    '-------------------------------------------
                    ' This is not a cutom table field since we have no EntityDescriptor
                    ' We only support RecordType.Product at this time
                    '-------------------------------------------
                    Me.FieldDescriptor = New Act.Framework.Database.FieldDescriptor(sFieldName, sFieldName, Act.Framework.RecordType.Product, Me.uicboACTDataType.SelectedItem)
                Else
                    '-------------------------------------------
                    ' Check if this field already exists based on the alias()
                    '-------------------------------------------
                    Dim manager As Act.Framework.CustomEntities.CustomSubEntityManager(Of CustomSubEntityDurkin)
                    manager = Me.HostFramework.CustomEntities.GetSubEntityManager(Of Durkin.Common.Classes.CustomSubEntityDurkin)(EntityDescriptor)

                    Dim CustomEntityFieldDescriptor As Act.Framework.CustomEntities.CustomEntityFieldDescriptor = CustomSubEntity.GetFieldDescriptorByAlias(Me.txtFieldName.Text, manager)

                    If Not CustomEntityFieldDescriptor Is Nothing Then
                        '-------------------------------
                        ' Can't Add DUPS
                        '-------------------------------
                        MessageBox.Show("Field '" + Me.txtFieldName.Text + "' already exists. Please use a different name.", DurkinEnumorators.PluginNames.Impact, MessageBoxButtons.OK, MessageBoxIcon.Warning)
                        Return False
                    End If

                    '-------------------------------
                    ' CREATE is a new Field
                    '-------------------------------
                    If Me.uicboACTDataType.SelectedItem = Act.Framework.Database.FieldDataType.Email Then
                        '----------------------------------------------------
                        ' CustomEntities ACTUALLY do not suppiort EMAIL fields
                        ' But IMPACT does support it as a CHARACTER field
                        ' NOTE we use a custom control named TextBoxDurkinHotlinked on the data entry form
                        '----------------------------------------------------
                        Me.FieldDescriptor = New Act.Framework.Database.FieldDescriptor(sFieldName, sFieldName, EntityDescriptor, Act.Framework.Database.FieldDataType.Email)
                    Else
                        Me.FieldDescriptor = New Act.Framework.Database.FieldDescriptor(sFieldName, sFieldName, EntityDescriptor, Me.uicboACTDataType.SelectedItem)
                    End If

                End If

            Else
                '-------------------------------
                ' UPDATE the existing name
                '-------------------------------
                If Me.FieldDescriptor.Name <> Durkin.Common.Utilities.Strings.StripInvalidCharacters(Me.txtFieldName.Text, "") Then
                    Me.FieldDescriptor.Name = Durkin.Common.Utilities.Strings.StripInvalidCharacters(Me.txtFieldName.Text, "")
                End If

            End If

            '-------------------------------
            ' ALLOW BLANK
            '-------------------------------
            Me.FieldDescriptor.AllowEmpty = Me.uiChkAllowBlank.Checked

            '-------------------------------
            ' GENERATE HISTORY
            '-------------------------------
            Me.FieldDescriptor.IsTracked = Me.uiChkGenerateHistory.Checked

            '-------------------------------
            ' PRIMARY FIELD - Duplicate
            '-------------------------------
            If ((((Me.FieldDescriptor.RecordType <> Act.Framework.RecordType.Opportunity) AndAlso _
                  (Me.FieldDescriptor.FieldDataType <> Act.Framework.Database.FieldDataType.Memo)) AndAlso _
                  (Me.FieldDescriptor.FieldDataType <> Act.Framework.Database.FieldDataType.Picture)) AndAlso _
                  (Me.FieldDescriptor.ColumnName <> "FULLNAME")) Then
                Me.FieldDescriptor.IsPrimary = Me.uiChkPrimaryField.Checked
            End If

            '-------------------------------
            ' ALLOW EDITING
            '-------------------------------
            Me.FieldDescriptor.IsReadOnly = Not Me.uichkAllowEditing.Checked

            '-------------------------------
            ' CALCULATED EXPRESSION
            ' Wating for ACT to catch up with calculatiions
            ' We need to see what the DEV team does with this field property
            '-------------------------------
            'If FieldDescriptor.Attributes.Contains(Act.Framework.Database.FieldProperty.CalculatedExpression) Then
            '    FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.CalculatedExpression) = New Act.Framework.Database.CalculatedExpressionAttribute("x=y+1")
            'End If

            '-------------------------------
            ' DECIMAL PRECESION  ( CURRENCY OR DECIMAL ONLY )
            '-------------------------------
            If Me.FieldDescriptor.Attributes.Contains(Act.Framework.Database.FieldProperty.DecimalPrecision) Then
                If Me.FieldDescriptor.FieldDataType = Act.Framework.Database.FieldDataType.Currency Or Me.FieldDescriptor.FieldDataType = Act.Framework.Database.FieldDataType.Decimal Then
                    Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.DecimalPrecision) = New Act.Framework.Database.DecimalPrecisionAttribute(Me.numLeftPrecision.Value, Me.numRightPrecision.Value)
                End If
            End If

            '-------------------------------
            ' DEFAULT VALUE
            '-------------------------------
            If Me.FieldDescriptor.Attributes.Contains(Act.Framework.Database.FieldProperty.DefaultValue) Then
                If Me.FieldDescriptor.FieldDataType = Act.Framework.Database.FieldDataType.YesNo Then
                    If Me.cboLogicalDefaultValue.SelectedItem Is Nothing Then
                        Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.DefaultValue) = New Act.Framework.Database.DefaultValueAttribute(False)
                    Else
                        Dim defaultvalue As Boolean = IIf(Me.cboLogicalDefaultValue.SelectedItem.ToString.ToUpper() = "TRUE", True, False)
                        Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.DefaultValue) = New Act.Framework.Database.DefaultValueAttribute(defaultvalue)
                    End If

                ElseIf Me.FieldDescriptor.FieldDataType = Act.Framework.Database.FieldDataType.Currency Then
                    Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.DefaultValue) = New Act.Framework.Database.DefaultValueAttribute(DirectCast(Me.uitxtDefautlValueNumeric.Value, Decimal))

                ElseIf Me.FieldDescriptor.FieldDataType = Act.Framework.Database.FieldDataType.Decimal Then
                    Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.DefaultValue) = New Act.Framework.Database.DefaultValueAttribute(DirectCast(Me.uitxtDefautlValueNumeric.Value, Decimal))

                ElseIf Me.FieldDescriptor.FieldDataType = Act.Framework.Database.FieldDataType.Number Then
                    Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.DefaultValue) = New Act.Framework.Database.DefaultValueAttribute(Convert.ToInt32(Me.uitxtDefautlValueNumeric.Value))

                Else
                    Try
                        '-------------------------------
                        ' This is wrapped in a try since if 
                        ' ACT ever decided to add the DefaultValue Attributes
                        ' onto a field such as Date or DateTime 
                        ' this next line will FAIL
                        '-------------------------------
                        Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.DefaultValue) = New Act.Framework.Database.DefaultValueAttribute(Me.uicboDefautlValue.Text)

                    Catch ex As Exception
                        ' do nothing
                        Dim ss As String = ""
                    End Try
                End If
            End If

            '-------------------------------
            ' LENGTH ATTRIBUT
            '-------------------------------
            If Me.FieldDescriptor.Attributes.Contains(Act.Framework.Database.FieldProperty.Length) Then
                If DirectCast(DirectCast(DirectCast(FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.Length), Act.Framework.Database.FieldDescriptorAttribute), Act.Framework.Database.LengthAttribute), Act.Framework.Database.LengthAttribute).Length <> Me.numFieldLength.Value Then
                    Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.Length) = New Act.Framework.Database.LengthAttribute(Me.numFieldLength.Value)
                End If
            End If

            '-------------------------------
            ' FIELD FORMAT / MASK
            '-------------------------------
            If Me.FieldDescriptor.Attributes.Contains(Act.Framework.Database.FieldProperty.Mask) Then
                Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.Mask) = New Act.Framework.Database.MaskAttribute(Me.uitxtFieldFormat.Text)
            End If

            '-------------------------------
            ' PICKLIST
            '-------------------------------
            If Me.uiChkDropDown.Checked = True Then
                '-----------------------------------------------------------------------------------
                ' *** DEV NOTE ***
                ' BUG IN ACT! Need to set the PickList to NONE first then save it
                ' so when we attach a different PickList is gets saved correctly ???
                ' THis bug goes back to ACT 2010 and since IMPACT still supports 2010
                ' we need to keep this code in place. "Luv you a long time"
                '-----------------------------------------------------------------------------------
                If Not (Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.PickList) Is Nothing) Then
                    Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.PickList) = Act.Framework.Database.PickListAttribute.None
                End If
                '---------------------------------------
                ' LOCK the Database
                '---------------------------------------
                Me.HostFramework.Database.LockDatabase(Act.Framework.DatabaseLockReason.SchemaChanges)
                '---------------------------------------
                ' Save the field changes
                '---------------------------------------
                Me.HostFramework.Fields.Save(Me.FieldDescriptor)
                '-----------------------------------------------------------------------------------
                ' *** DEV NOTE ***
                ' BUG IN ACT! See above
                '-----------------------------------------------------------------------------------

                If Me.uicboPickList.SelectedItem = "(none)" Then
                    If Not (Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.PickList) Is Nothing) Then
                        Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.PickList) = Act.Framework.Database.PickListAttribute.None 'New Act.Framework.Database.PickListAttribute(Nothing, True, False, True, False)
                    End If
                Else
                    Dim pickList As Act.Framework.PickLists.PickList = Me.HostFramework.PickLists.GetPickList(Me.uicboPickList.SelectedItem)

                    Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.PickList) = _
                         New Act.Framework.Database.PickListAttribute(pickList, _
                                                                     Me.uiChkLimitToList.Checked, _
                                                                     Me.uiChkMultiSelect.Checked, _
                                                                     Me.uiChkTypeAhead.Checked, _
                                                                     Me.uiChkShowDescription.Checked)

                End If
            Else
                If Not (Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.PickList) Is Nothing) Then
                    Me.FieldDescriptor.Attributes(Act.Framework.Database.FieldProperty.PickList) = Act.Framework.Database.PickListAttribute.None
                End If
            End If

            '-----------------------------------------------------
            ' *** DEV NOTE ***
            '  3RD PANEL IN WIZARD
            ' IMPACT SUITE does not support triggger at this time 
            '-----------------------------------------------------
            'Dim TriggerAttribute As Act.Framework.Database.TriggerAttribute = FieldDescriptor.Attributes.Item(Act.Framework.Database.FieldProperty.ChangeTrigger)
            'Dim FocusTrigger As Act.Framework.Database.FocusAttribute = FieldDescriptor.Attributes.Item(Act.Framework.Database.FieldProperty.FocusTrigger)
            'Dim LostFocusTrigger As Act.Framework.Database.LostFocusAttribute = FieldDescriptor.Attributes.Item(Act.Framework.Database.FieldProperty.LostFocusTrigger)
            If Me.FieldDescriptor.Attributes.Contains(Act.Framework.Database.FieldProperty.LostFocusTrigger) Then

            End If
            If Me.FieldDescriptor.Attributes.Contains(Act.Framework.Database.FieldProperty.FocusTrigger) Then

            End If
            If Me.FieldDescriptor.Attributes.Contains(Act.Framework.Database.FieldProperty.ChangeTrigger) Then

            End If

            '------------------------------------------------
            ' Check if we are passing an alias because
            ' ACTFM.Fields.Save will fail in the alias = String.Empty
            '------------------------------------------------
            If Me.FieldDescriptor.Alias = String.Empty Then
                Me.FieldDescriptor.Alias = FieldDescriptor.Name
            End If

            If Me.FieldDescriptor.HasChanges = True Then
                '------------------------------------------------
                ' Get the current Cursor to reset after we refresh
                '------------------------------------------------
                Dim tmpCurrentCursor As Cursor
                tmpCurrentCursor = Windows.Forms.Cursor.Current

                '------------------------------------------------
                ' Set the Mouse cursor to our Custom WaitCursor
                '------------------------------------------------
                Windows.Forms.Cursor.Current = Cursors.WaitCursor

                '---------------------------------------------------------
                ' Suspend Refresh Notifications
                '---------------------------------------------------------
                Act.Framework.Database.DescriptorBaseManager.SuspendNotification()

                '---------------------------------------
                ' LOCK the Database
                '---------------------------------------
                Me.HostFramework.Database.LockDatabase(Act.Framework.DatabaseLockReason.SchemaChanges)

                '---------------------------------------
                ' Save the field changes
                '---------------------------------------
                Me.HostFramework.Fields.Save(Me.FieldDescriptor)

                '---------------------------------------
                ' Convert the TYPE if the user so desires
                '---------------------------------------
                If Me.FieldDescriptor.FieldDataType <> Me.uicboACTDataType.SelectedItem Then
                    Me.HostFramework.Fields.Convert(Me.FieldDescriptor, Me.uicboACTDataType.SelectedItem)
                End If

                '---------------------------------------
                ' Unlock the database
                '---------------------------------------
                Me.HostFramework.Database.UnlockDatabase()

                '---------------------------------------------------------
                ' Restart Refresh Notifications
                '---------------------------------------------------------
                'Act.Framework.Database.DescriptorBaseManager.ResumeNotification()
                Me.HostFramework.Fields.RefreshSchema()

                '------------------------------
                ' reset the PMouse cursor
                '------------------------------
                Windows.Forms.Cursor.Current = tmpCurrentCursor

            End If

            Return True

        Catch ex1 As System.NotImplementedException
            MessageBox.Show(ex1.Message, DurkinEnumorators.PluginNames.Impact, MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False

        Catch ex As Exception
            MessageBox.Show(ex.Message, DurkinEnumorators.PluginNames.Impact, MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

        Return True

    End Function

 

 

 

 

Copper Contributor
Posts: 123
Country: Canada

Re: Change a Custom Sub-Entity field DisplayName?

Thanks for the post Jim.  I was hoping to do this with the basic SDK that comes with act.  It is good to know that there are other tools to use if need be!