SDK中如何在SAP B1的UDT中添加数据?
How to add data in UDT of SAP B1 in SDK?
我在SDK中SAP B1的UDT中添加记录时出现问题
我所有的代码
Public Class SystemForm
Private oCompany As SAPbobsCOM.Company
Private WithEvents SBO_Application As SAPbouiCOM.Application
Private Sub SetApplication()
Dim SboGuiApi As SAPbouiCOM.SboGuiApi
Dim sConnectionString As String
SboGuiApi = New SAPbouiCOM.SboGuiApi()
sConnectionString = Command()
SboGuiApi.Connect(sConnectionString)
SBO_Application = SboGuiApi.GetApplication()
End Sub
Public Sub New()
MyBase.New()
SetApplication()
End Sub
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If pVal.FormTypeEx = "UDO_FT_RPRL" AndAlso pVal.ActionSuccess = False AndAlso pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED AndAlso pVal.ItemUID = "2" AndAlso pVal.FormMode = 3 Then
Dim oUsrTbl As SAPbobsCOM.UserTable
Dim Res As Integer
oCompany = New SAPbobsCOM.Company
oUsrTbl = oCompany.UserTables.Item("@TODD")
oUsrTbl.Code = "1"
oUsrTbl.Name = "189"
oUsrTbl.UserFields.Fields.Item("U_Amount").Value = 4000
Res = oUsrTbl.Add()
If Res = 0 Then
SBO_Application.MessageBox("Added")
Else
SBO_Application.MessageBox("Error, failed to add Record")
End If
End If
End Sub
End Class
我尝试做研究但没有帮助
实际上我想做的是,如果我点击 UDO 的添加按钮,它会更新我的名为 @TODD 的 UDT,但是如果我点击代码上方的添加按钮,则会出现以下错误消息“Addon 9000058 failed with exception; Event类型:1".
请任何人帮助我
您在创建实例 oCompany 后缺少对 DIAPI 的 Connect() 方法的调用。在调用它之前,您需要设置连接上下文,方法是指定服务器和登录名,或者从 UI-API 连接获取会话上下文。假设您的 UI-API 对象被称为 SBO_Application:
Dim Cookie as String = oCompany.GetContextCookie()
Dim conStr as String = SBO_Application.Company.GetConnectionContext(Cookie)
oCompany.SetSboLoginContext(conStr)
oCompany.Connect()
(未经测试的代码)
显然,您可能希望在继续之前检查 Connect 调用是否成功。
这是我正在使用的连接代码,在我的例子中,它设置了一个 'oCompany' 对象,可用于交易和 'DoQuery' 查询。
SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
oCompany.CompanyDB = "DATABASE_NAME";
oCompany.Server = "FTHANA01:30015"; // Your server name goes here
oCompany.LicenseServer = "FTHANA01:30000";
oCompany.SLDServer = "FTHANA01:40000";
oCompany.DbUserName = "SAPSYSTEM";
oCompany.DbPassword = psw1;
oCompany.UserName = "SAP Username";
oCompany.Password = psw2;
// We are using a SAP Hana database
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
oCompany.UseTrusted = true;
int ret = oCompany.Connect();
string errMsg = oCompany.GetLastErrorDescription();
int ErrNo = oCompany.GetLastErrorCode();
if (ErrNo != 0)
(we have an error)
else
(success)
需要数据库登录凭据和用户登录凭据。
我在SDK中SAP B1的UDT中添加记录时出现问题
我所有的代码
Public Class SystemForm
Private oCompany As SAPbobsCOM.Company
Private WithEvents SBO_Application As SAPbouiCOM.Application
Private Sub SetApplication()
Dim SboGuiApi As SAPbouiCOM.SboGuiApi
Dim sConnectionString As String
SboGuiApi = New SAPbouiCOM.SboGuiApi()
sConnectionString = Command()
SboGuiApi.Connect(sConnectionString)
SBO_Application = SboGuiApi.GetApplication()
End Sub
Public Sub New()
MyBase.New()
SetApplication()
End Sub
Private Sub SBO_Application_ItemEvent(ByVal FormUID As String, ByRef pVal As SAPbouiCOM.ItemEvent, ByRef BubbleEvent As Boolean) Handles SBO_Application.ItemEvent
If pVal.FormTypeEx = "UDO_FT_RPRL" AndAlso pVal.ActionSuccess = False AndAlso pVal.EventType = SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED AndAlso pVal.ItemUID = "2" AndAlso pVal.FormMode = 3 Then
Dim oUsrTbl As SAPbobsCOM.UserTable
Dim Res As Integer
oCompany = New SAPbobsCOM.Company
oUsrTbl = oCompany.UserTables.Item("@TODD")
oUsrTbl.Code = "1"
oUsrTbl.Name = "189"
oUsrTbl.UserFields.Fields.Item("U_Amount").Value = 4000
Res = oUsrTbl.Add()
If Res = 0 Then
SBO_Application.MessageBox("Added")
Else
SBO_Application.MessageBox("Error, failed to add Record")
End If
End If
End Sub
End Class
我尝试做研究但没有帮助
实际上我想做的是,如果我点击 UDO 的添加按钮,它会更新我的名为 @TODD 的 UDT,但是如果我点击代码上方的添加按钮,则会出现以下错误消息“Addon 9000058 failed with exception; Event类型:1".
请任何人帮助我
您在创建实例 oCompany 后缺少对 DIAPI 的 Connect() 方法的调用。在调用它之前,您需要设置连接上下文,方法是指定服务器和登录名,或者从 UI-API 连接获取会话上下文。假设您的 UI-API 对象被称为 SBO_Application:
Dim Cookie as String = oCompany.GetContextCookie()
Dim conStr as String = SBO_Application.Company.GetConnectionContext(Cookie)
oCompany.SetSboLoginContext(conStr)
oCompany.Connect()
(未经测试的代码)
显然,您可能希望在继续之前检查 Connect 调用是否成功。
这是我正在使用的连接代码,在我的例子中,它设置了一个 'oCompany' 对象,可用于交易和 'DoQuery' 查询。
SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
oCompany.CompanyDB = "DATABASE_NAME";
oCompany.Server = "FTHANA01:30015"; // Your server name goes here
oCompany.LicenseServer = "FTHANA01:30000";
oCompany.SLDServer = "FTHANA01:40000";
oCompany.DbUserName = "SAPSYSTEM";
oCompany.DbPassword = psw1;
oCompany.UserName = "SAP Username";
oCompany.Password = psw2;
// We are using a SAP Hana database
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_HANADB;
oCompany.UseTrusted = true;
int ret = oCompany.Connect();
string errMsg = oCompany.GetLastErrorDescription();
int ErrNo = oCompany.GetLastErrorCode();
if (ErrNo != 0)
(we have an error)
else
(success)
需要数据库登录凭据和用户登录凭据。