cancel
Showing results for 
Search instead for 
Did you mean: 

UserFieldsMD

Former Member
0 Kudos

Hello,

The DI's object UserFieldsMD object requires the field id parameter in the GetByKey method. I want to check the existence of user field before add or update in my Add on. but, i don't know the field id. Any solution or sample code??

Regards,

Kit

Accepted Solutions (0)

Answers (1)

Answers (1)

rasmuswulff_jensen
Active Contributor
0 Kudos

Most people use the CUFD table to check if a UDF exist:

Something like this


/// <summary>
/// Check if a field exist on a specific table
/// </summary>
/// <param name="tableName">The name of the table</param>
/// <param name="uid">The name of the field</param>
/// <returns>If the field exist</returns>
public static bool ExistField(string tableName, string uid)
        {
            try
            {
                B1Recordset rs = B1Recordset.DoQuery("SELECT COUNT(*) AS udfcount FROM CUFD WHERE TableID LIKE '%" + tableName + "' AND AliasID='" + uid + "'");
                int udfcount= rs.GetValueAsInteger("udfcount");
                rs = null;
                GC.Collect();
                return (udfcount== 1);
            }
            catch 
            {
                return false;
            }
        }