我遇到了在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的Add按钮然后它会更新我的UDT @TODD,但如果我点击上面的Add按钮会带来以下错误消息" Addon 9000058失败,但有例外;事件类型:1"。
请有人帮助我
答案 0 :(得分: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呼叫是否成功。
答案 1 :(得分:0)
这是我正在使用的代码,用于连接并在我的情况下设置一个可用于事务和“ DoQuery”查询的“ oCompany”对象。
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)
同时需要数据库登录凭据和用户登录凭据。