Community
Showing results for 
Search instead for 
Do you mean 
Reply

'The parameter descriptor cannot be null' error adding field to custom entity

Copper Contributor
Posts: 11
Country: USA

'The parameter descriptor cannot be null' error adding field to custom entity

ACT! by Sage Premium 2009 (11.0) Version 11.1.183.0, Hotfix 1, Hotfix 2

VB.Net 2008

 

Short History

Created Travel custom entity in db1. Imported data. Can add, edit and delete records.

Created Documents custom entity. works

Created GroupTravel custom entity. works

 

Created program to add field to custom entity (from code on this site to give credit where credit is due).

Keep getting "The parameter descriptor cannot be null. Parameter descriptor." error adding a field to Travel.

Able to add field to other custom entities.

 

Saved copy of db1 as db2.

Created TravelTemp custom entity in db2.

Copied, using sdk, Travel items to TravelTemp

Deleted Travel ce, recreated Travel ce.

Copied TravelTemp items back to new Travel ce.

Can now add new fields to Travel ce.

 

No new data had been added so I deleted db1 and then saved copy of db2 to db1.

db1 works well.

Added Children ce.

Can add new field to all custom entities except Travel after using for awhile.

 

Does anyone know what would change in the Travel ce or in the database structure to keep giving me the "The parameter descriptor cannot be null. Parameter descriptor." error?

I have checked the descriptor object and it is not null and it works for all other custom entities.

 

Here is code for adding a field.

 

Imports Act.Framework
Imports Act.Framework.Database
Imports Act.Framework.ComponentModel
Imports Act.Framework.CustomEntities
Imports System.IO
Imports System.Text.Encoding

Public Class Form1
Dim strUserNametoKeep As String
Dim strDatabaseName As String = ""
Dim ActFW As New Act.Framework.ActFramework

Private ActApp As Act.UI.ActApplication 'reference to act application
Private descriptor As Act.Framework.CustomEntities.CustomEntityDescriptor 'custom entity
Private ContactDescriptor As Act.Framework.CustomEntities.CustomEntityDescriptor
Private Sub btnSelectDatabase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectDatabase.Click

GetDatabaseName()
If Me.txtDatabaseName.Text <> String.Empty Then
Me.txtUserName.Focus()
Else
Me.btnSelectDatabase.Focus()
End If


End Sub


Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtUserName.Text = "Computer Department"
txtFieldLength.Text = "30"
End Sub
Private Sub btnAddField_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddField.Click
Me.Cursor = Cursors.WaitCursor

Try
ActFW.LogOn(txtDatabaseName.Text, Me.txtUserName.Text, "")
Catch ex As Act.Framework.Database.InvalidDatabaseNameException
MessageBox.Show(ex.Message, "Trying to log on")
Exit Sub
End Try


'Lock Database - Schema Changes

Try
'lock the database since we are performing a schema change
ActFW.Database.LockDatabase(DatabaseLockReason.SchemaChanges)

'get the custom entity
Dim Descriptor As Act.Framework.CustomEntities.CustomEntityDescriptor
Descriptor = ActFW.CustomEntities.GetCustomEntityDescriptor(txtSubEntity.Text)

If Not Descriptor Is Nothing Then

'add the Field
Try

'Select Case grpFieldType.Text
Select Case True
Case radDate.Checked '"Date"
Dim field As Act.Framework.Database.FieldDescriptor
field = New FieldDescriptor(txtFieldName.Text, UCase(txtSubEntity.Text) & _
"_" & UCase(txtFieldName.Text), Descriptor, FieldDataType.Date)
field.AllowEmpty = chkAllowEmpty.Checked
field.IsTracked = chkIsTracked.Checked
ActFW.Fields.Save(field)
Case radCharacter.Checked '"Character"
Dim field As Act.Framework.Database.FieldDescriptor
'Dim field As Act.Framework.CustomEntities.CustomEntityFieldDescriptor
field = New Act.Framework.Database.FieldDescriptor(txtFieldName.Text, UCase(txtSubEntity.Text) & _
"_" & UCase(txtFieldName.Text), Descriptor, FieldDataType.Character)
'MessageBox.Show("Descriptor Name: " & Descriptor.Name.ToString & ". Type: " & Descriptor.EntityType.ToString & ". Parent: " & _
'Descriptor.ParentEntity.ToString & ". Is null: " & IsNothing(Descriptor))
field.Attributes(Act.Framework.Database.FieldProperty.Length) = New LengthAttribute(CInt(txtFieldLength.Text))
field.AllowEmpty = chkAllowEmpty.Checked
field.IsTracked = chkIsTracked.Checked
ActFW.Fields.Save(field)

Case radNumber.Checked ' "Number"
Dim field As Act.Framework.Database.FieldDescriptor
field = New FieldDescriptor(txtFieldName.Text, UCase(txtSubEntity.Text) & _
"_" & UCase(txtFieldName.Text), Descriptor, FieldDataType.Number)

field.AllowEmpty = chkAllowEmpty.Checked
field.IsTracked = chkIsTracked.Checked
ActFW.Fields.Save(field)
Case radYesNo.Checked '"YesNo"
Dim field As Act.Framework.Database.FieldDescriptor
field = New FieldDescriptor(txtFieldName.Text, UCase(txtSubEntity.Text) & _
"_" & UCase(txtFieldName.Text), Descriptor, FieldDataType.YesNo)
'field.AllowEmpty = chkAllowEmpty.Checked
field.Attributes(Act.Framework.Database.FieldProperty.DefaultValue) = New DefaultValueAttribute(vbFalse)
field.IsTracked = chkIsTracked.Checked
ActFW.Fields.Save(field)
End Select

'ActApp.ActFramework.Fields.Save(field)



Catch ex As Act.Framework.CustomEntities.CustomSubEntity.CustomEntityFieldCollection.MissingFieldException
MsgBox(ex.Message)
End Try
Else
MessageBox.Show("The " & txtSubEntity.Text & " entity does not exist.")
End If

Catch ex As Exception
MessageBox.Show(ex.Message)

If Err.Number = 5 Then
MessageBox.Show("The sub-entity '" & Me.txtSubEntity.Text & "' does not exist.")
Else
MessageBox.Show(Err.Description & " - " & Err.Number & " - Adding Entity Field")
End If
Finally 'Schema changes made - Unlock Database
ActFW.Database.UnlockDatabase()
End Try



Exit_btnAddField:
'clean up
ActFW.Database.UnlockDatabase()
Me.Cursor = Cursors.Arrow
MessageBox.Show("All Done")


End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub CheckforInput()
If Me.txtUserName.Text <> String.Empty And Me.txtDatabaseName.Text <> String.Empty _
And Me.txtSubEntity.Text <> String.Empty Then
Me.btnAddField.Enabled = True
Me.btnAddField.Focus()
Else
MessageBox.Show("Database name (.pad file), User Name and Entity name are all required.")
End If
End Sub

Private Sub txtUserName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtUserName.Leave
If Me.txtUserName.Text = String.Empty Then
MsgBox("Need a user name.")
Me.txtUserName.Focus()
End If
End Sub


Private Sub GetDatabaseName()
'Get the Database name
Dim objOpenFileDialog As New OpenFileDialog
With objOpenFileDialog
.Filter = "Act Database (*.pad)|*.pad|All Files (*.*)|*.*"
.FilterIndex = 1
.Title = "Open Act Database"

End With
GetDatabasePath:
'show the dialog
If objOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
'if the open button on the dialog box was clicked, then load the file name selected
strDatabaseName = objOpenFileDialog.FileName
objOpenFileDialog.Dispose()
objOpenFileDialog = Nothing
Me.txtDatabaseName.Text = strDatabaseName
Else
If objOpenFileDialog.ShowDialog = Windows.Forms.DialogResult.Cancel And Me.txtDatabaseName.Text = String.Empty Then
MessageBox.Show("No Database was selected. You cannot proceed with this process.")
Exit Sub
Else
Exit Sub
End If
End If


End Sub

Private Sub txtSubEntity_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSubEntity.Leave
'CheckforInput()
End Sub

Private Sub DeleteField(ByVal aliasname As String, ByVal descriptor As Act.Framework.CustomEntities.CustomEntityDescriptor)

'get the fields
Dim fields As Act.Framework.Database.FieldDescriptorCollection = ActApp.ActFramework.Fields.GetFields(descriptor)

For Each field As Act.Framework.Database.FieldDescriptor In fields
If field.Alias = aliasname Then
'delete the field
ActApp.ActFramework.Fields.Delete(field)
End If
Next

End Sub

Private Sub CreateField(ByVal ftype As Act.Framework.Database.FieldDataType, ByVal displayname As String, _
ByVal aliasName As String, ByVal descriptor As Act.Framework.CustomEntities.CustomEntityDescriptor)

Try
'create the field
Dim field As Act.Framework.Database.FieldDescriptor = New Act.Framework.Database.FieldDescriptor(displayname, _
aliasName, descriptor, ftype)

'save the field
ActApp.ActFramework.Fields.Save(field)

Catch ex As Exception
MessageBox.Show(ex.Message, "ACT", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try

End Sub


End Class

Well, now I've done it. I did a repair and reindex, ole/db rebuild and schema rebuild and now I get the same error for all entities.

Is there something somewhere in the database structure that won't let a field be added?

 

I have the whole project zipped up but I don't know how or where to upload for others to get.

 

Thanks. John