Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Set a UDF Value on System Form using UI API

Former Member
0 Likes
650

Hi everyone,

I am wondering what's the best way of setting a UDF on system form.

Here is my situation:

I have a button on the sales quotation and this button opens a new sales order and sets U_OQUTNO value as the quotation's DocNum.

// oForm is Quotation Form

var oForm = Application.SBO_Application.Forms.Item(pVal.FormUID);

// activeForm is Sales Order Form

Application.SBO_Application.ActivateMenuItem("2050"); var activeForm = Application.SBO_Application.Forms.ActiveForm;

activeForm.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE;

activeForm.Freeze(true);

// setting Quotation's DocNum to Sales Order's U_OQUTNO which is bound to Item_7

((SAPbouiCOM.EditText)activeForm.Items.Item("Item_7").Specific).Value = ((SAPbouiCOM.EditText)oForm.Items.Item("8").Specific).Value;

activeForm.Freeze(false);

This is working but it's so slow and also if the item is not visible the code throws an exception when setting value. I wrote code to copy quotation lines to sales order lines, as I mentioned before, this way is so slow. I researched in previously asked questions and found an answer that told about using XML is the fastest way to manipulating data on the screen. I tried like below:

var quotationDBDataSource = oForm.DataSources.DBDataSources.Item("OQUT");

string quotationXML = quotationDBDataSource.GetAsXML();

quotationXML = quotationXML.Replace(" encoding=\"UTF-16\" ", "");

XElement xDocQuotation = XElement.Parse(quotationXML);

string quotDocNum = xDocQuotation.Descendants("uid").First(x => x.Value == "DocNum").Parent.Element("value").Value;

var orderDBDataSource = activeForm.DataSources.DBDataSources.Item("ORDR");

string orderXML = orderDBDataSource.GetAsXML();

orderXML = orderXML.Replace(" encoding=\"UTF-16\" ", "");

XElement xDocOrder = XElement.Parse(orderXML);

// throws an exception that has message as there is no node called U_QUOTNO in XML

xDocOrder.Descendants("uid").First(x => x.Value == "U_OQUTNO").Parent.Element("value").Value = quotDocNum;

orderDBDataSource.LoadFromXML(xDocOrder.ToString());

I realized that ORDR table's XML hasn't got any node called U_QUOTNO. But there is a user-defined field called U_QUOTNO in ORDR table. So this scenario did not work for me.

Finally, what is the best way to set values on a form using UI API?

Best regards

Gökmen ESKİN

0 REPLIES 0