Skip to Content

Pass Value to UDF Field

Hello

I'm beginner SAP SDK programming and i can't seem to find a way to pass value to UDF in Goods Issue.

UDF field : U_CardCode 'OIGE'

Any kind of help will be appreciated.

if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST)
                {
                    IChooseFromListEvent oCFLEvento = null;
                    oCFLEvento = ((IChooseFromListEvent)(pVal));
                    string sCFL_ID = null;
                    sCFL_ID = oCFLEvento.ChooseFromListUID;
                    Form oForm = null;
                    oForm = SAPbouiCOM.Framework.Application.SBO_Application.Forms.Item(FormUID);
                    SAPbouiCOM.ChooseFromList oCFL = null;
                    oCFL = oForm.ChooseFromLists.Item(sCFL_ID);
                    if (oCFLEvento.BeforeAction == false)
                    {
                        SAPbouiCOM.DataTable oDataTable = null;
                        oDataTable = oCFLEvento.SelectedObjects;
                        string val = null;
                        string val1 = null;
                        try
                        {
                            val = Convert.ToString(oDataTable.GetValue(0, 0));
                            val1 = Convert.ToString(oDataTable.GetValue(1, 0));
                        }
                        catch (Exception ex)
                        {


                        }
                        if ((pVal.ItemUID == "BPCode"))
                        {
                            oForm.DataSources.UserDataSources.Item("UD_BPCode").Value = val;
                            oForm.DataSources.UserDataSources.Item("UD_BPName").Value = val1;                              HERE I WANNA SET THE FIELD USING VAL.
                        }
                    }
                }

ss1.png (14.1 kB)
Add a comment
10|10000 characters needed characters exceeded

  • Hello Ankit Chauhan,

    I did some changes to my code following your guide.

    Now i'm facing general failure error when CFL event in BP Code is triggered.

    Here is error:

    An exception of type 'System.Runtime.InteropServices.COMException' occurred in ZigZag Goods Issue by Customer.exe but was not handled in user code
    
    
    Additional information: General Failure
    
    

    And here is my code after few adding few lines:

    private void SBO_Application_ItemEvent(string FormUID, ref ItemEvent pVal, out bool BubbleEvent)
            {
                BubbleEvent = true;
                Debug.WriteLine("FormUID:"+pVal.FormTypeEx);
                if (pVal.FormTypeEx == "720")
                {
                    if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_CHOOSE_FROM_LIST)
                    {
                        
                        IChooseFromListEvent oCFLEvento = null;
                        oCFLEvento = ((IChooseFromListEvent)(pVal));
                        string sCFL_ID = null;
                        sCFL_ID = oCFLEvento.ChooseFromListUID;
                        Form oForm = null;                 
                        oForm = SAPbouiCOM.Framework.Application.SBO_Application.Forms.Item(FormUID);
                        Form oForm1 = null;
                        oForm1 = SAPbouiCOM.Framework.Application.SBO_Application.Forms.GetForm("-720", 1);
                        this.oEdit = (SAPbouiCOM.EditText)oForm1.Items.Item("U_CardCode").Specific;
                        SAPbouiCOM.ChooseFromList oCFL = null;
                        oCFL = oForm.ChooseFromLists.Item(sCFL_ID);
                        if (oCFLEvento.BeforeAction == false)
                        {
                            SAPbouiCOM.DataTable oDataTable = null;
                            oDataTable = oCFLEvento.SelectedObjects;
                            string val = null;
                            string val1 = null;
                            try
                            {
                                val = Convert.ToString(oDataTable.GetValue(0, 0));
                                val1 = Convert.ToString(oDataTable.GetValue(1, 0));
                            }
                            catch (Exception ex)
                            {
    
    
                            }
                            if ((pVal.ItemUID == "BPCode"))
                            {
                                oForm.DataSources.UserDataSources.Item("UD_BPCode").Value = val;
                                oForm.DataSources.UserDataSources.Item("UD_BPName").Value = val1;
                                oEdit.Value = "TEST";
                            }
                        }
                    }
                }
            }
    

    Thanks for your attention.

    And i will take my time to keep UDF Form open after i solve this issue.

    Update:

    Also tried adding catch exception like following still no value is passed to UDF.

    try
                                {
                                    oEdit.Value = val;
                                    Debug.WriteLine("TEXT: "+oEdit.Value);
                                }
                                catch (Exception ex)
                                {
    
    
                                }
    
  • Hi Gombo Khorloo,

    UDF Form will be having the Form ID as -720. If you would like to do it via UI API only, you can do it as below:

    SAPbouiCOM.Form oForm = (SAPbouiCOM.Form)SBO_Application.Forms.GetForm(-720, 1);
    SAPbouiCOM.EditText oEdit = (SAPbouiCOM.EditText)oForm.Items.Item("CustomerCode").Specific;
    oEdit.Value = "Test";

    You need to keep in mind that the UDF Form should always be opened in this case. Otherwise, the code will fail because it will not be able to get the Form -720 if UDF Form is closed.

    If it does not suit to your requirement, please explain the issue in details.

    Kind regards,

    ANKIT CHAUHAN

    SAP Business One Support

  • Hi Gombo,

    Thank you for visiting SAP Community to get answers to your questions. I am here to help you to get the most out of it.

    First of all, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't done so already), as it provides tips for preparing questions that draw responses from our members.

    Please also make sure you're using all appropriate tags, so the right experts can find your question. Overall, the more details you provide, the more likely it is that members will be able to assist you. Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question - but if that happens, you can leave more details in a comment).

    Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.

    Best,
    Lena (SAP Community Moderator)

Related questions

1 Answer

  • Best Answer
    Posted on Aug 07, 2020 at 12:37 PM

    Fixed by adding one more line:

    try
                                {
                                    oEdit.Value = val;
                                }
                                catch (Exception ex)
                                {
                                    oEdit.Value = val;
    
                                }
    Add a comment
    10|10000 characters needed characters exceeded