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

Re: CAnnot get the Actual Field Size in application

Hi,

 

Thanks, i can see now i am getting some field sizes.. but i think there is some underlying issue i am having

 

I will post an update once i understand what my problem is

 

thanks for all your assistance, been very helpfull

Copper Contributor
Posts: 16
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Hello

 

Thanks for all the help

 

got it working :-)

 

 public int GetACTFieldSize(string FieldDisplayName)
        {
            FieldDescriptorManager oFDM = _ACTFramework.Fields;
            FieldDescriptorCollection oFDColl = oFDM.GetFields(RecordType.Contact);
            foreach (FieldDescriptor f in oFDColl)
            {
               
                if (f.Alias.ToUpper() == FieldDisplayName.ToUpper())
                {
                    LengthAttribute lA = (LengthAttribute)f.Attributes[FieldProperty.Length];
                    return lA.Length;
                }
            }
            return 0;
        }

 

 

Still picking up stuff, didnt know how to cast in C#  do now

 

cheers again

 

Copper Contributor
Posts: 16
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

Just wondered

 

can you not directly access a field without needed to loop through all the fields?

 

the loop slows processing down when there are a large number of fields

Bronze Elite Contributor
Posts: 2,119
Country: United_Kingdom

Re: CAnnot get the Actual Field Size in application

public void GetFieldLength()
{
FieldDescriptorCollection oFDC = oFram.Fields.GetFields(RecordType.Contact);
System.Windows.Forms.MessageBox.Show(((LengthAttribute)oFDC.Find("Company").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

Hi,

 

I would just like to share my method to get the Size of any given database field

 

I have made it generic to the entities we have access too and deals with Currency/Date/Number fields , its not perfect but its easy to add too now if needed

 

Many thanks to vivek for you help Smiley Happy

 

public int GetACTFieldSize(string EntityName, string FieldDisplayName)
        {
            RecordType RecType = RecordType.Company;

            switch (EntityName.ToLower())
            {

                case "contact":
                    RecType = RecordType.Contact;
                    break;

                case "company":
                    RecType = RecordType.Company;
                    break;

                case "opportunity":
                    RecType = RecordType.Opportunity;
                    break;

                case "product":
                    RecType = RecordType.Product;
                    break;

                case "group":
                    RecType = RecordType.Group;
                    return 0;
            }

            try
            {
                FieldDescriptorCollection oFDC = _ACTFramework.Fields.GetFields(RecType);
                FieldDescriptor ThisField = oFDC.Find(FieldDisplayName.ToUpper());

                // Try and return the Length Attribute - otherwise fail and then try Currency instead
                if (ThisField.FieldDataType == FieldDataType.DateTime)
                {
                    // DateTime is 19 characters . set to 20 as it will never be a problem.
                    return 20;
                }

                try
                {
                    LengthAttribute lA = (LengthAttribute)ThisField.Attributes[FieldProperty.Length];

                    if (lA != null)
                    {
                        return lA.Length;
                    }
                }

                catch (Exception)
                {
                    // dont care about error here, fall through and deal with other options
                }

                try
                {
                    CurrencyPrecisionAttribute curA = (CurrencyPrecisionAttribute)ThisField.Attributes[FieldProperty.DecimalPrecision];
                    return curA.RightPrecision + curA.LeftPrecision + 1;
                }

                catch (Exception)
                {
                    // dont care about error here, fall through and deal with other options
                }
            }

            catch (Exception)
            {
                // dont care about error here, fall through and return 0 as the default
            }
            return 0;
        }