Skip to Content
author's profile photo Former Member
Former Member

Valid Value in Marketing Doc UDF

Hi,

We have a UDF in marketing document which is having two valid values.I need to add a new valid value to the list through DI API. However

it is returning error -5002 (No matching records found). Also is it possible to change the description of an exixsting valid value of the UDF?

If yes, how is that possible?

The code we are using is given below. Any help in troublshooting.? Using SAP B1 90 PL 12

int id = 0;

SAPbobscom.Recordset rs;

rs = (SAPbobscom.Recordset rs)oCompany.GetBusinessObject(SAPbobscom.Recordset rs);

rs.DoQuery("select FieldID from CUFD where TableID='ODLN' and AliasID = 'ChargeTyp'");

if (rs.RecordCount > 0)

id = Convert.ToInt32(rs.Item("FieldID").ToString());

SAPbobsCom.UserFieldsMD ufd1 = (SAPbobsCom.UserFieldsMD)

oCompany.GetBusinessObject(SAPbobsCom.UserFieldsMD);

if (ufd1.GetByKey("ODLN", id))

{

ufd1.Size = 25;

ufd1.ValidValues.Value = "Flat Per Shipment Rate";

ufd1.ValidValues.Description = "Flat Rate per Shipment";

ufd1.ValidValues.Add();

int r = ufd1.Update();

}

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Dec 04, 2015 at 01:08 PM

    Hi Rejish,

    Change the order of your code following this:

    ufd1.ValidValues.Add();

    ufd1.ValidValues.Value = "Flat Per Shipment Rate";

    ufd1.ValidValues.Description = "Flat Rate per Shipment";

    And I think it is not possible alter lenght of your field.

    And yes, it is possible alter description of an old valid value.

    You need get the index of your valid value with this query:

    SELECT UFD1.IndexID FROM CUFD

    INNER JOIN UFD1

    ON CUFD.TableID = UFD1.TableID

    AND CUFD.FieldID = UFD1.FieldID

    WHERE CUFD.TableID = '{0}'

    AND CUFD.AliasID = '{1}'

    AND UFD1.FldValue = '{2}'

    And then:

    ufd1.ValidValues.SetCurrentLine(Convert.ToInt32(IndexId));

    change description:

    ufd1.ValidValues.Description = "Your new description";

    udf1.Update();

    Regards,

    Diego

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Rejish,

      Diego is absolutely right, first you have to prepare the line of you valid value :

      ufd1.ValidValues.Add();


      I share with you a complete code for the update of UDF :

      private void UpdateUDFiFExists(string TableName, string fieldName)

      {

      int nbres = 0;

      QueryFirstValueRec("SELECT T0.\"AliasID\" FROM CUFD T0 WHERE T0.\"TableID\"='" + TableName + "' AND T0.\"AliasID\"='" + fieldName + "'", true, out nbres);

      if (nbres != 0)

      {

      int fieldID = (int) QueryFirstValueRec("SELECT T0.\"FieldID\" FROM CUFD T0 WHERE T0.\"TableID\"='" + TableName + "' AND T0.\"AliasID\"='" + fieldName + "'", true);

      SAPbobsCOM.UserFieldsMD myUserFieldsMD = (SAPbobsCOM.UserFieldsMD)oCompany .GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields);

      if (myUserFieldsMD.GetByKey(TableName, fieldID))

      {

      GC.Collect();

      GC.WaitForPendingFinalizers();

      myUserFieldsMD.Description = "New descrip";

      myUserFieldsMD.ValidValues.Add();

      myUserFieldsMD.ValidValues.Value = "Value";

      myUserFieldsMD.ValidValues.Description = "ValueDesc";

      int res = myUserFieldsMD.Update();

      if (res != 0)

      Application.SBO_Application.SetStatusBarMessage(oCompany.GetLastErrorDescription());

      System.Runtime.InteropServices.Marshal.ReleaseComObject(myUserFieldsMD);

      GC.WaitForPendingFinalizers();

      GC.Collect();

      }

      }

      }

      Regards,

      Mohamed.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.