Community
Showing results for 
Search instead for 
Do you mean 
Reply

CAnnot get the Actual Field Size in application

Copper Contributor
Posts: 16
Country: United_Kingdom

CAnnot get the Actual Field Size in application

I have been trying for hours now and cannot find how this is done.

 

using the act framework outside of Act (not a plugin)

 

I have tried many possible solutions but none work

 

Using C#

 

I can browse the fields size property but its a protected member and I dont know how to retrieve the value i need correctly.

 

Here is my sample code

 

DBFieldDescriptor

RecordField = GetACTFieldDescriptor(fieldname);

Act.Framework.MutableEntities.

MutableEntityFieldDescriptor test = ((Act.Framework.MutableEntities.MutableEntityFieldDescriptor

)(RecordField));

Now according to the IDE I can see there is .columns.size but i cannot get to it, how is the best way?

I cannot believe the DBFieldDescriptor does not expose this value!! or am I being stupid?

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Hi Darren,

 

If you use the Act.Framework.Database.FieldDescriptor class then you can use the Attribute[] to obtain the FieldLength property:

 

FieldDescriptor f;

MessageBox.Show(f.Attributes[FieldProperty.Length].ToString());

 

HTH

 

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Copper Contributor
Posts: 16
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Hi,

 

Thanks for your reply however I did spot the Database FieldDescriptor had access to a fields size but I couldnt work out how to set (in your example) f = my field

 

How to I select the field i want to get the Attributes for?

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Hiya,

 

I haven't tested this and haven't used IntelliSense so there may be some typos but hopefully you get the idea.

 

ActFramework oFram;

FieldDescriptor myField;

 

FieldDescriptorManager oFDM = oFram.Fields;

FieldDescriptorCollection oFDColl = oFDM.GetFields(RecordType.Contact);

 

foreach(FieldDescriptor f in oFDColl){

if(f.Alias == "TheFieldAliasIAmAfter")

myField.Attributes[FieldProperty.Length] = f.Attributes[FieldProperty.Length];

}

 

Or if you wanted to just set to a specific number you could:

 

myField.Attributes[FieldProperty.Length] = new LegthAttribute(20);

 

HTH

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Copper Contributor
Posts: 16
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Hi

 

I have modified your code to run but , sorry to say there is still no physical value i can use

 

I have a method to pass this back

 

        public string GetACTFieldSize(string FieldDisplayName)
        {

            try
            {
              
                FieldDescriptorManager oFDM = _ACTFramework.Fields;
                FieldDescriptorCollection oFDColl = oFDM.GetFields(RecordType.Contact);

                foreach (FieldDescriptor f in oFDColl)
                {

                    if (f.Alias == FieldDisplayName.ToUpper())
                    {
                        string ss = f.Attributes[FieldProperty.Length].ToString();
                        FieldDescriptor myField = f;
                        myField.Attributes[FieldProperty.Length] = f.Attributes[FieldProperty.Length];
                        return myField.Attributes[FieldProperty.Length].ToString();
                        break;
                    }
                }
                return "0";
            }

            catch (Exception)
            {
                //
            }
            return "";
        }

 

If i interogate the field i get

 

f.Attributes[FieldProperty.Length].ToString()

"Act.Framework.Database.LengthAttribute"

 

The browser still shows them as non public members - this is very frustrating

 

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

hmm try
f.Attributes[FieldProperty.Length].Length.ToString()
Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Copper Contributor
Posts: 16
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

I tried that before

 

Error 1 'Act.Framework.Database.FieldDescriptorAttribute' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument of type 'Act.Framework.Database.FieldDescriptorAttribute' could be found (are you missing a using directive or an assembly reference?) ACTHelperClass.cs 93 91 MeterAutoProcess

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Ok sorry my mistake I must be loosing the plot or something! Smiley Surprised)
The f.Attributes[FieldProperty.Length] returns a FieldDescriptorAttribute which needs to be casted as a LengthAttribute so:

LengthAttribute lA = (LengthAttribute)f.Attributes[FieldProperty.Length];
MessageBox.Show(lA.Length.ToString());

Let me know if you still have problems and I will fire up VS and try myself!
Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog
Copper Contributor
Posts: 16
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Hi

 

Looked promissing but the LA does not end up with anything in it....  if i break point it after the new code and check in the Imeediate window i get

 

The name 'lA' does not exist in the current context,

Bronze Elite Contributor
Posts: 2,115
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Ok just tested this out and it works. On my dB it gave a field length of 128 which is correct for the COmpany field in Contacts.

 

 

public void GetFieldLength()
        {
            FieldDescriptorCollection oFDC = oFram.Fields.GetFields(RecordType.Contact);
            foreach (FieldDescriptor f in oFDC)
            {
                if (f.Alias == "COMPANY")
                {
                    string s = f.Attributes[FieldProperty.Length].ToString();
                    LengthAttribute lA = (LengthAttribute)f.Attributes[FieldProperty.Length];
                    System.Windows.Forms.MessageBox.Show(lA.Length.ToString());
                }
            }
        }

 I'm using ACT! 2011 Premium SP1. But can still see references to this way back in the ACT! 2007 SDK as well.

 

 

 

Vivek Gargav
Caldere Associates Ltd.
www.caldere.com
vgargav@caldere.com
My Blog