cancel
Showing results for 
Search instead for 
Did you mean: 

How to create UDF link to child production order

jeff_putnam
Explorer
0 Kudos

Hi experts, I'm trying to replicate functionality from a 3rd party add-on that is no longer supported. Somehow they did what's shown below. In a PdO they have a Child PdO UDF which is populated with the child PdO # and when you click it the child PdO is opened. I've been able to create the PdO's and their children and populate Child PdO with the correct number. What I don't know how to do is make it blue and underlined and open the child PdO when clicked. Thanks for your help.

Accepted Solutions (0)

Answers (2)

Answers (2)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert

Hi jeff.putnam,

SetCellFontStyle method updates the font style of a cell in a matrix or a grid. Refer to SAP Business One SDK Help for the same.

To open Production Order, you can set the object type.

Kind regards,

ANKIT CHAUHAN

SAP Business One Support

jeff_putnam
Explorer
0 Kudos

Thank you, Ankit. Sorry it took so long to respond. I got pulled away on another project. You definitely got me started in the right direction. For anyone else, here's the code I ended up with which works for me. I know there's little or no error handling, just the basics. I'm working in SAP B1 9.2. childPdOIndex is a global

if ((pVal.FormType == 65211 /* PdO Form */) && (pVal.Before_Action == true))  // Before_Action means SAP hasn't processed it yet
{
    oProdOrderForm = My_Application.Forms.GetFormByTypeAndCount(pVal.FormType, pVal.FormTypeCount);
    SAPbouiCOM.Matrix oMatrix = oProdOrderForm.Items.Item("37").Specific;

    // When form loads or changes with arrows, set all ChildPdO fields to bold, underlined, blue
    if ((pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_LOAD) ||
        (pVal.ItemUID == "74" && pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED))
    {

        // Find the index of the ChildPdO field.  SAP doesn't appear to have a better way.  Only doing this at form load/change shouldn't be too terrible
        for (int j = 0; j < oMatrix.Columns.Count; j++) 
        { 
            if (oMatrix.Columns.Item(j).UniqueID == "U_ChildPdO") 
            { 
                childPdOIndex = j; 
                break;
            } 
        }
        if (childPdOIndex == -1)
        {
            MessageBox.Show("ChildPdO column not found!  Cannot link to child PdOs");
            return;
        }

        // Loop through ChildPdO fields and set font to blue & underlined
        int blueFontColor = Color.Blue.R | (Color.Blue.G << 😎 | (Color.Blue.B << 16);
        for (int i = 1; i < oMatrix.RowCount; i++)           // Note 
        {
            oMatrix.CommonSetting.SetCellFontColor(i, childPdOIndex, blueFontColor);
            oMatrix.CommonSetting.SetCellFontStyle(i, childPdOIndex, SAPbouiCOM.BoFontStyle.fs_Underline | SAPbouiCOM.BoFontStyle.fs_Bold);
        }
    }
    // When ChildPdO column is clicked, open that production order.  NEEDS CHECKING FOR VALID NUMBER, ETC.
    else if ((pVal.EventType == SAPbouiCOM.BoEventTypes.et_CLICK) &&
            (pVal.ItemUID == "37")  &&          // Matrix is item 37 on PdO form
            (pVal.ColUID == "U_ChildPdO") &&    // ChildPdO column clicked on
            (!pVal.InnerEvent))
    {
        string childPdO = oMatrix.Columns.Item("U_ChildPdO").Cells.Item(pVal.Row).Specific.Value.Trim();

        My_Application.OpenForm(SAPbouiCOM.BoFormObjectEnum.fo_ProductionOrder, "", childPdO);
    }
}