cancel
Showing results for 
Search instead for 
Did you mean: 

How i could change a value on a Userfield Form ?

Former Member
0 Kudos

I need change automaticaly a value from a UserField Form (CtrlShiftU) before add a Sales Order but i tried to use a EditText component and it couldn't be done because there isn't support for this.

Any one knows how can i change it?

Accepted Solutions (1)

Accepted Solutions (1)

former_member201110
Active Contributor
0 Kudos

Hi Thiago,

The type of UI API object you need to use depends on how the UDF is set up. For example, if you have set any valid values for the field then the control on the UDF tab will be a combobox and not an edittext.

Something like the following should work:


private void SetUserDefinedValue(string sFormType, int iFormCount, string sFieldName, string sValue)
{
    // sFormType = FormTypeEx property of the main form to which the UDF form is attached
    // iFormCount = FormTypeCount property of the main form
    // sFieldName = The UDF field name eg U_MYFIELDNAME
    // sValue = The value you want to set

    try
    {
        SAPbouiCOM.EditText sboEdit;
        SAPbouiCOM.ComboBox sboCombo;

        SAPbouiCOM.Form sboUDFForm = null;
        try
        {
            // Get the UDF form attached to the main form
            sboUDFForm = _sboApp.Forms.GetForm("-" + sFormType, iFormCount);
        }
        catch
        {
            // UDF form wasn't open so active menu option to open the form
            _sboApp.ActivateMenuItem("6913");
            sboUDFForm = _sboApp.Forms.GetForm("-" + sFormType, iFormCount);
        }

        if (sboUDFForm != null)
        {
            SAPbouiCOM.Item sboItem = (SAPbouiCOM.Item)sboUDFForm.Items.Item(sFieldName);
            switch (sboItem.Type)
            {
                case (SAPbouiCOM.BoFormItemTypes.it_EDIT):
                case (SAPbouiCOM.BoFormItemTypes.it_EXTEDIT):
                    sboEdit = (SAPbouiCOM.EditText)sboItem.Specific;
                    sboEdit.String = sValue;
                    break;

                case (SAPbouiCOM.BoFormItemTypes.it_COMBO_BOX):
                    sboCombo = (SAPbouiCOM.ComboBox)sboItem.Specific;
                    sboCombo.Select(sValue, SAPbouiCOM.BoSearchKey.psk_ByValue);
                    break;
            }
        }
        else
        {
            _sboApp.SetStatusBarMessage("Error: Unable to activate the UDF form", SAPbouiCOM.BoMessageTime.bmt_Medium, true);
        }
    }
    catch (Exception ex)
    {
        _sboApp.SetStatusBarMessage("Error: " + ex.Message, SAPbouiCOM.BoMessageTime.bmt_Medium, true);
    }
}

I haven't added all the possible control types but you can add these as required.

Another way to approach the solution is to add a control to the main form and bind this to your UDF field using the DBDataSource that already exists on the system form. You can then write to the field on the main form using the relevant UI API control type rather than having to access the UDF tab. I've found this to be a better solution in most cases because you cannot guarantee that the UDF is available on the UDF tab (because UDF settings allow the user to hide or disable the field or put it in a separate category).

Kind Regards,

Owen

Answers (2)

Answers (2)

Former Member
0 Kudos

Sorry, but, now is working ...

Things from computing world!

😕

Former Member
0 Kudos

actualy my code is:


try
                {
                    SAPbouiCOM.ComboBox CB;
                    SAPbouiCOM.EditText ED;
                    SAPbouiCOM.Form mainForm;
                    int count;
                    String U_id;
                    
                    mainForm = (SAPbouiCOM.Form)globals.SBO_Application.Forms.Item(oFormUID);
                    count = mainForm.TypeCount;
                    mainForm = (SAPbouiCOM.Form)globals.SBO_Application.Forms.Item(globals.SBO_Application.Forms.GetForm("-139", count).UniqueID);
                    CB = (SAPbouiCOM.ComboBox)mainForm.Items.Item("U_mmbCxq").Specific;
                    CB.Select("Sim", SAPbouiCOM.BoSearchKey.psk_ByDescription);
                    ED = (SAPbouiCOM.EditText)mainForm.Items.Item("U_MMBSTATUS").Specific;
                    ED.Value = "1";
}
catch (Exception e)
{
         Console.WriteLine(e.Message);
}

but aways that I try to declare CB it has a problem!

Former Member
0 Kudos

Hi,

What Exception you Got When you Run your Code

Mohamed Zubair