<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Set a UDF Value on System Form using UI API in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/set-a-udf-value-on-system-form-using-ui-api/m-p/11877720#M1960374</link>
    <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
  &lt;P&gt;I am wondering what's the best way of setting a UDF on system form.&lt;/P&gt;
  &lt;P&gt;Here is my situation:&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;// oForm is Quotation Form&lt;/P&gt;
  &lt;P&gt;var oForm = Application.SBO_Application.Forms.Item(pVal.FormUID);&lt;/P&gt;
  &lt;P&gt;// activeForm is Sales Order Form&lt;/P&gt;
  &lt;P&gt;Application.SBO_Application.ActivateMenuItem("2050"); var activeForm = Application.SBO_Application.Forms.ActiveForm; &lt;/P&gt;
  &lt;P&gt; activeForm.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE;&lt;/P&gt;
  &lt;P&gt;activeForm.Freeze(true);&lt;/P&gt;
  &lt;P&gt;// setting Quotation's DocNum to Sales Order's U_OQUTNO which is bound to Item_7&lt;/P&gt;
  &lt;P&gt;((SAPbouiCOM.EditText)activeForm.Items.Item("Item_7").Specific).Value = ((SAPbouiCOM.EditText)oForm.Items.Item("8").Specific).Value;&lt;/P&gt;
  &lt;P&gt;activeForm.Freeze(false);&lt;/P&gt;
  &lt;P&gt;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:&lt;/P&gt;
  &lt;P&gt; var quotationDBDataSource = oForm.DataSources.DBDataSources.Item("OQUT"); &lt;/P&gt;
  &lt;P&gt; string quotationXML = quotationDBDataSource.GetAsXML(); &lt;/P&gt;
  &lt;P&gt; quotationXML = quotationXML.Replace(" encoding=\"UTF-16\" ", ""); &lt;/P&gt;
  &lt;P&gt; XElement xDocQuotation = XElement.Parse(quotationXML); &lt;/P&gt;
  &lt;P&gt; string quotDocNum = xDocQuotation.Descendants("uid").First(x =&amp;gt; x.Value == "DocNum").Parent.Element("value").Value; &lt;/P&gt;
  &lt;P&gt; var orderDBDataSource = activeForm.DataSources.DBDataSources.Item("ORDR"); &lt;/P&gt;
  &lt;P&gt; string orderXML = orderDBDataSource.GetAsXML(); &lt;/P&gt;
  &lt;P&gt; orderXML = orderXML.Replace(" encoding=\"UTF-16\" ", ""); &lt;/P&gt;
  &lt;P&gt; XElement xDocOrder = XElement.Parse(orderXML); &lt;/P&gt;
  &lt;P&gt;// throws an exception that has message as there is no node called U_QUOTNO in XML&lt;/P&gt;
  &lt;P&gt; xDocOrder.Descendants("uid").First(x =&amp;gt; x.Value == "U_OQUTNO").Parent.Element("value").Value = quotDocNum;&lt;/P&gt;
  &lt;P&gt;orderDBDataSource.LoadFromXML(xDocOrder.ToString());&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;Finally, what is the best way to set values on a form using UI API?&lt;/P&gt;
  &lt;P&gt;Best regards&lt;/P&gt;
  &lt;P&gt;Gökmen ESKİN&lt;/P&gt;</description>
    <pubDate>Sun, 09 Jun 2019 21:39:24 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2019-06-09T21:39:24Z</dc:date>
    <item>
      <title>Set a UDF Value on System Form using UI API</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/set-a-udf-value-on-system-form-using-ui-api/m-p/11877720#M1960374</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
  &lt;P&gt;I am wondering what's the best way of setting a UDF on system form.&lt;/P&gt;
  &lt;P&gt;Here is my situation:&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;// oForm is Quotation Form&lt;/P&gt;
  &lt;P&gt;var oForm = Application.SBO_Application.Forms.Item(pVal.FormUID);&lt;/P&gt;
  &lt;P&gt;// activeForm is Sales Order Form&lt;/P&gt;
  &lt;P&gt;Application.SBO_Application.ActivateMenuItem("2050"); var activeForm = Application.SBO_Application.Forms.ActiveForm; &lt;/P&gt;
  &lt;P&gt; activeForm.Mode = SAPbouiCOM.BoFormMode.fm_ADD_MODE;&lt;/P&gt;
  &lt;P&gt;activeForm.Freeze(true);&lt;/P&gt;
  &lt;P&gt;// setting Quotation's DocNum to Sales Order's U_OQUTNO which is bound to Item_7&lt;/P&gt;
  &lt;P&gt;((SAPbouiCOM.EditText)activeForm.Items.Item("Item_7").Specific).Value = ((SAPbouiCOM.EditText)oForm.Items.Item("8").Specific).Value;&lt;/P&gt;
  &lt;P&gt;activeForm.Freeze(false);&lt;/P&gt;
  &lt;P&gt;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:&lt;/P&gt;
  &lt;P&gt; var quotationDBDataSource = oForm.DataSources.DBDataSources.Item("OQUT"); &lt;/P&gt;
  &lt;P&gt; string quotationXML = quotationDBDataSource.GetAsXML(); &lt;/P&gt;
  &lt;P&gt; quotationXML = quotationXML.Replace(" encoding=\"UTF-16\" ", ""); &lt;/P&gt;
  &lt;P&gt; XElement xDocQuotation = XElement.Parse(quotationXML); &lt;/P&gt;
  &lt;P&gt; string quotDocNum = xDocQuotation.Descendants("uid").First(x =&amp;gt; x.Value == "DocNum").Parent.Element("value").Value; &lt;/P&gt;
  &lt;P&gt; var orderDBDataSource = activeForm.DataSources.DBDataSources.Item("ORDR"); &lt;/P&gt;
  &lt;P&gt; string orderXML = orderDBDataSource.GetAsXML(); &lt;/P&gt;
  &lt;P&gt; orderXML = orderXML.Replace(" encoding=\"UTF-16\" ", ""); &lt;/P&gt;
  &lt;P&gt; XElement xDocOrder = XElement.Parse(orderXML); &lt;/P&gt;
  &lt;P&gt;// throws an exception that has message as there is no node called U_QUOTNO in XML&lt;/P&gt;
  &lt;P&gt; xDocOrder.Descendants("uid").First(x =&amp;gt; x.Value == "U_OQUTNO").Parent.Element("value").Value = quotDocNum;&lt;/P&gt;
  &lt;P&gt;orderDBDataSource.LoadFromXML(xDocOrder.ToString());&lt;/P&gt;
  &lt;P&gt;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.&lt;/P&gt;
  &lt;P&gt;Finally, what is the best way to set values on a form using UI API?&lt;/P&gt;
  &lt;P&gt;Best regards&lt;/P&gt;
  &lt;P&gt;Gökmen ESKİN&lt;/P&gt;</description>
      <pubDate>Sun, 09 Jun 2019 21:39:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/set-a-udf-value-on-system-form-using-ui-api/m-p/11877720#M1960374</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-06-09T21:39:24Z</dc:date>
    </item>
  </channel>
</rss>

