cancel
Showing results for 
Search instead for 
Did you mean: 

Add Item to System Form using XML

Former Member
0 Kudos

Hi,

Could some one send me the source code to add a checkbox in a system form by using XML?

I need the XML form and the code.

I have no problem using XML for SBO form stand alone; but I have problem to add items to existing system form.

I am using the UI 11 SystemFormManipulation and I have remived the C# code to use XML in added folder.

Thank you,

Rune

Accepted Solutions (1)

Accepted Solutions (1)

former_member201110
Active Contributor

Hi Rune,

Here's how you would add a checkbox to the sales order form:

Create an XML file as follows:


<?xml version="1.0" encoding="UTF-16"?>
<Application>
  <forms>
    <action type="update">
      <form FormType="139" uid="">
        <datasources>
          <dbdatasources>
            <action type="add"/>
          </dbdatasources>
          <userdatasources>
            <action type="add">
                    <datasource size="1" type="9" uid="Check1"/>
            </action>
          </userdatasources>
        </datasources>
        <Menus/>
        <items>
          <action type="add">
            <item uid="Check1" type="121" left="125" tab_order="0" width="100" top="65" height="14" 

visible="1" enabled="1" from_pane="0" to_pane="0" disp_desc="0" right_just="0" description="" linkto="" 

forecolor="-1" backcolor="-1" text_style="0" font_size="-1" supp_zeros="0" AffectsFormMode="1">
              <AutoManagedAttribute/>
              <specific caption="My Checkbox" AffectsFormMode="1" val_on="Y" val_off="N">
                <databind databound="1" table="" alias="Check1"/>
              </specific>
            </item>
          </action>
        </items>
        <DataBrowser/>
      </form>
    </action>
  </forms>
</Application>

Note: Make sure you save the file with Unicode encoding in the same folder as your addon executable (or in the debug folder when running it within VS).

Next, here's a simple code example of how to load the XML as the sales order form is being loaded:


using Microsoft.VisualBasic;
using System;
using System.Xml;

...

private void SBO_Application_ItemEvent( string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent ) 
{
	BubbleEvent = true;
            
        if ( pVal.FormType == 139 & pVal.EventType != SAPbouiCOM.BoEventTypes.et_FORM_UNLOAD && pVal.Before_Action == true ) 
        { 
        	oOrderForm = SBO_Application.Forms.GetFormByTypeAndCount( pVal.FormType, pVal.FormTypeCount );

                if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_FORM_LOAD && pVal.Before_Action == true)
                {
                    UpdateFormByXML("NewCheckbox.xml", pVal.FormUID);
                }  
	} 
} 

private void UpdateFormByXML(string sFileName, string sFormUID)
{
	try
	{
                string sXPath = "Application//forms//action//form//@uid";
                string sPath = System.Environment.CurrentDirectory + "\\";

                XmlDocument xDoc = new XmlDocument();

                xDoc.Load(sPath + sFileName);

                XmlNode xNode = xDoc.SelectSingleNode(sXPath);
                xNode.InnerText = sFormUID;

                string sXML = xDoc.InnerXml.ToString();

                SBO_Application.LoadBatchActions(ref sXML);
	}
	catch (Exception ex)
	{
		SBO_Application.SetStatusBarMessage(ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, true);
	}
}

To keep things simple, I've missed out the code needed to connect to the SBO client etc and I've hardcoded certain string values. I inserted this code in to the SDK sample you mentioned and it runs ok on my system (you should see a new checkbox at the top of the sales order form, just below the Customer Ref No. field).

Also, have a look here:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/ebe72e9e-0301-0010-979e-d37...

Kind Regards,

Owen

Former Member
0 Kudos

Hi Owen,

Thank you very much!

Very nice code sample!

And in C#, Perfect!

Wish you a great weekend!

Rune

Former Member
0 Kudos

PS,

I have problem with sXPath, what do you do here?

string sXPath = "Application//forms//action//form//@uid";

Nussi
Active Contributor
0 Kudos

iam not 100% sure - but i guess that


                string sPath = System.Environment.CurrentDirectory + "\\";
 
                XmlDocument xDoc = new XmlDocument();
 
                xDoc.Load(sPath + sFileName);
                string sXML = xDoc.InnerXml.ToString();
 
                SBO_Application.LoadBatchActions(ref sXML);

is enough

regards

David

Former Member
0 Kudos

Thanks David,

But it is looking for a uid?

That's way Owen has sXPath and sPath.

My error is: Form - Reserved / Illegal form Unique ID [66000-2]. Form Unique Id : " (The error message stops here, I assume it is missing some text...)

Nussi
Active Contributor
0 Kudos

when you don't edit the xml and put the uid in by hand you have to use owens code.

the singlenode code was selecting the tag with the uid="" and than he set the correct formuid.

so you have two possibilities to solve it

regards

David

Former Member
0 Kudos

I keyed in @uid in Owen's XML form <form FormType="139" uid="@uid">; same error...

Sorry, but send me the code of both examples

Thank you,

Rune

Nussi
Active Contributor
0 Kudos

well Rune,

this should be enough:

sXML = sXML.Replace("uid=""", "uid="" + sFormUID + """);

it replaces in the XML the uid="" to uid="yourformuid"

i know Owens Code was better - iam sorry ...

iam going to bed rune - if you fail i have a look at it tomorrow !

regards

David

Edited by: David Nussböck on Apr 18, 2008 10:53 PM

Answers (0)