cancel
Showing results for 
Search instead for 
Did you mean: 

Add UDF to OITM Table

Former Member
0 Kudos

Hi everyone

I was trying to create new udf for OITM and OCRD system tables.

When I checked CUFD table after ran below function,

OITM's tableid is stored as @OITM instead of OITM but OCRD table is stored as OCRD.

I had a problem only OITM table.

I'm runing on B1 2004 PL32.

Please help me!!!!

oUFields = oCompany.GetBusinessObject (SAPbobsCOM.BoObjectTypes.oUserFields)

oUFields.TableName = "OITM"

oUFields.Name = "PrcGrp"

oUFields.Description = "PriceGroup"

oUFields.Type = SAPbobsCOM.BoFieldTypes.db_Alpha

oUFields.Size = 8

oUFields.Add

Me.ReleaseUFields()

oUFields.TableName = "OCRD"

oUFields.Name = "PrcGrp"

oUFields.Description = "PriceGroup"

oUFields.Type = SAPbobsCOM.BoFieldTypes.db_Alpha

oUFields.Size = 8

oUFields.Add

Me.ReleaseUFields()

Accepted Solutions (0)

Answers (2)

Answers (2)

Gianluigi
Product and Topic Expert
Product and Topic Expert
0 Kudos

You may also want to use B1DE to do this in a simpler and quicker way. Have a look at this thread:

Former Member
0 Kudos

Hello Joanne,

I used the following code to test it in 2005 SP0 PL7, and everything is fine. Could you please test it in another machine? And if it still happens, please open a message to SAP support.

In addition, please try to create a UDF for ITEM manually inside of SAP Business One, and check the result in CUFD.

Hope this helps,

Nick

Dim oUserFieldsMD As SAPbobsCOM.UserFieldsMD

oUserFieldsMD = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)

oUserFieldsMD.TableName = "OITM"

oUserFieldsMD.Name = "Hello"

oUserFieldsMD.Description = "Hello"

oUserFieldsMD.Type = SAPbobsCOM.BoFieldTypes.db_Numeric

oUserFieldsMD.EditSize = 2

lRetCode = oUserFieldsMD.Add

Message was edited by: Nick He

rasmuswulff_jensen
Active Contributor
0 Kudos

I use this method to check if a field exits... I use the LIKE clause to avoid the problem...

       public static bool ExistField(string tableName, string FieldName)
        {
            try
            {
                B1Recordset rs = B1Recordset.DoQuery("SELECT COUNT(*) AS antal FROM CUFD WHERE TableID LIKE '%" + tableName + "' AND AliasID='" + FieldName + "'");
                int antal = rs.GetValueAsInteger("antal");
                rs = null;
                GC.Collect();
                return (antal == 1);
            }
            catch 
            {
                return false;
            }
        }

Former Member
0 Kudos

Hello.

I use this function (C++), this work perfect to find if user field exists.



SAPbobsCOM::IUserFieldsMDPtr m_pUserFieldsMD = m_Cmp->GetBusinessObject( SAPbobsCOM::oUserFields );
	SAPbobsCOM::IRecordsetPtr m_pRecordSet = m_Cmp->GetBusinessObject( SAPbobsCOM::BoRecordset );
	_bstr_t m_Query = L"SELECT TableID, AliasID FROM [CUFD] WHERE TableID = '" + m_TableID 
			+ "' and AliasID = '" + m_AliasID + "'";
	if ( m_pRecordSet->DoQuery( m_Query ) != S_OK ) 'if don`t find'
	{
m_App->SetStatusBarMessage(" Don`t find",SAPbouiCOM::bmt_Short, VARIANT_TRUE );
		return -3;
	}
	if ( m_pRecordSet->GetRecordCount() > 0 )
		return S_OK;    'find'
	else
		return -2;   'don`t find'

I use ' to comment, not // like in C++.

Hope this helps.

Sorry for my english.

Regards

Kamil Wydra

Message was edited by: Kamil Wydra