Un gusto, saludos a todos los participantes.
Mi nombre es Marlo Chena, desde Paraguay, soy Analista de Sistemas, trabajando
hace un buen tiempo, y ahora estoy comenzando hace unos días en este nuevo mundo,
el de SAP B1 y la programación en SDK.
Cuando se instala en Cliente SAP, tambien se crea una carpeta (C:\Program Files (x86)\SAP\SAP Business One SDK\Samples) donde se puede acceder a ejemplos de programacion SDK.
Estoy estancado en uno de ellos (C:\Program Files (x86)\SAP\SAP Business One SDK\Samples\COM DI\VB .NET\07.Permissions) correspondiente al item de Permisos(estoy utilizando Visual Basic.net - Visual Studio 2012), quisiera compartir el inconveniente a ver si alguien puede ayudarme a solucionarla o indicarme que “No” estoy haciendo o que hago mal.
Esta son las capturas de pantalla para que sea más ilustrativo lo que esta ocurriendo.
Cuando se intenta crear Forms por ejemplo a partir de ventanas definidas por usuarios o ventanas nativas del B1(por ejemplo Form=150/Datos Maestros de articulos), siempre crea el Form, siendo que no debe permitirlo, pero cuando creas un Form a partir de un type cualquiera, si salta el error de permiso.
Aqui les coloco el código para ver que puede ser:
****************************************************************************************************************************
*********************************INICIO DEL CÓDIGO*****************************************************************
'****************************************************************************
' SAP MANAGE DI API 2007 SDK Sample
'****************************************************************************
'
' Copyright (c) SAP MANAGE
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'****************************************************************************
Option Explicit On
Public Class frmPermission
Inherits System.Windows.Forms.Form
Private WithEvents SBO_Application As SAPbouiCOM.Application
'Error handling variables
Public sErrMsg As String
Public lErrCode As Integer
Public lRetCode As Integer
Private Sub SetApplication()
'*******************************************************************
'// Use an SboGuiApi object to establish connection
'// with the SAP Business One application and return an
'// initialized appliction object
'*******************************************************************
Dim SboGuiApi As SAPbouiCOM.SboGuiApi
Dim sConnectionString As String
SboGuiApi = New SAPbouiCOM.SboGuiApi
sConnectionString = Environment.GetCommandLineArgs.GetValue(1)
'// connect to a running SBO Application
Try ' If there's no active application the connection will fail
SboGuiApi.Connect(sConnectionString)
Catch ' Connection failed
System.Windows.Forms.MessageBox.Show("No SAP Business One Application was found")
End
End Try
'// get an initialized application object
SBO_Application = SboGuiApi.GetApplication()
'SBO_Application.MessageBox("Hello World")
End Sub
'****************************************************************************
' This function is called when the form is loaded.
' It performs various initialization procedures.
'****************************************************************************
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmbDBType.SelectedIndex = 3
SetApplication()
End Sub
'****************************************************************************
' This function connects to the database
'****************************************************************************
Private Sub Connect()
Cursor = System.Windows.Forms.Cursors.WaitCursor 'Change mouse cursor
' Set connection properties
oCompany.CompanyDB = cmbCompany.Text
oCompany.UserName = txtUSer.Text
oCompany.Password = txtPassword.Text
'Try to connect
lRetCode = oCompany.Connect()
If lRetCode <> 0 Then ' if the connection failed
oCompany.GetLastError(lErrCode, sErrMsg)
MsgBox("Connection Failed - " & sErrMsg, MsgBoxStyle.Exclamation, "Default Connection Failed")
Else
LoadUsers()
grpPermission.Enabled = True
End If
If oCompany.Connected Then ' if connected
Me.Text = Me.Text & " - Connected to " & oCompany.CompanyDB
grpConn.Enabled = False
grpPermission.Enabled = True
End If
Cursor = System.Windows.Forms.Cursors.Default 'Change mouse cursor
End Sub
'****************************************************************************
' This function is called when the "Connect" button is called
'****************************************************************************
Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
Connect()
End Sub
'****************************************************************************
' This function adds a new permission
'****************************************************************************
Private Sub AddToPermissionTree()
Dim RetVal As Long
Dim ErrCode As Long
Dim ErrMsg As String
Dim oPermission As SAPbobsCOM.UserPermissionTree
oPermission = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserPermissionTree)
oPermission.Name = txtPermissionName.Text
oPermission.PermissionID = txtPermissionID.Text
oPermission.UserPermissionForms.FormType = Trim(txtFormType.Text)
oPermission.Options = SAPbobsCOM.BoUPTOptions.bou_FullReadNone
RetVal = oPermission.Add()
oCompany.GetLastError(RetVal, ErrMsg)
If RetVal <> 0 Then
MessageBox.Show(ErrMsg)
Else
grpPermission.Enabled = False
grpSetPermission.Enabled = True
End If
End Sub
'****************************************************************************
' This function loads all the users in the company to a list box
'****************************************************************************
Private Sub LoadUsers()
Dim oUsers As SAPbobsCOM.Users
Dim oRecordSet As SAPbobsCOM.Recordset
oUsers = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUsers)
oRecordSet = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
oRecordSet.DoQuery("SELECT * FROM OUSR")
oUsers.Browser.Recordset = oRecordSet
oUsers.Browser.Refresh()
oUsers.Browser.MoveFirst()
' add to list box
Dim i As Integer
lstUsers.Items.Add(oUsers.UserCode, False)
For i = 1 To oUsers.Browser.RecordCount() - 1
oUsers.Browser.MoveNext()
lstUsers.Items.Add(oUsers.UserCode, False)
Next
'While Not (oUsers.Browser.EoF)
' lstUsers.Items.Add(oUsers.UserCode, False)
' oUsers.Browser.MoveNext()
'End While
txtNewFormType.Text = txtFormType.Text
End Sub
'****************************************************************************
' This function responds to a click in the "Add Permission" button
'****************************************************************************
Private Sub cmdNewPermission_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNewPermission.Click
AddToPermissionTree()
End Sub
'****************************************************************************
' This sub assigns the permission to users
'****************************************************************************
Private Sub cmdUserPermission_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUserPermission.Click
Dim oUser As SAPbobsCOM.Users
oUser = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUsers)
Dim i As Integer
For i = 0 To lstUsers.CheckedIndices.Count - 1
Dim j = lstUsers.CheckedIndices.Item(i)
lRetCode = oUser.GetByKey(j + 1)
oCompany.GetLastError(lRetCode, sErrMsg)
If lRetCode <> 0 Then
MessageBox.Show(sErrMsg)
End If
oUser.UserPermission.Add()
oUser.UserPermission.SetCurrentLine(0)
oUser.UserPermission.PermissionID = txtPermissionID.Text
'****************PARA DAR AUTORIZACION COMPLETA**************************
oUser.UserPermission.Permission = SAPbobsCOM.BoPermission.boper_ReadOnly
lRetCode = oUser.Update
oCompany.GetLastError(lRetCode, sErrMsg)
If lRetCode <> 0 Then
MessageBox.Show(sErrMsg)
End If
MessageBox.Show("Definido permiso ")
Next i
End Sub
'****************************************************************************
' This sub creates a form with s specified type
'****************************************************************************
Private Sub CreateForm()
Dim oForm As SAPbouiCOM.Form
Dim cp As SAPbouiCOM.FormCreationParams
cp = SBO_Application.CreateObject(SAPbouiCOM.BoCreatableObjectType.cot_FormCreationParams)
cp.BorderStyle = SAPbouiCOM.BoFormBorderStyle.fbs_Fixed
cp.FormType = Trim(txtNewFormType.Text)
cp.UniqueID = "MyID"
Try
oForm = SBO_Application.Forms.AddEx(cp)
oForm.Visible = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
'****************************************************************************
' This function responds to a click in the "Create Form" button
'****************************************************************************
Private Sub cmdNewForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNewForm.Click
CreateForm()
End Sub
Private Sub cmdGetCompanyList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetCompanyList.Click
oCompany = New SAPbobsCOM.Company
' Init Connection Properties
'oCompany.DbServerType = cmbDBType.SelectedIndex + 1
'oCompany.Server = "localhost" ' change to your company server
oCompany.DbServerType = 10
oCompany.Server = "EVERLONG\MSSQLSERVER2016"
oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English ' change to your language
oCompany.UseTrusted = False
oCompany.DbUserName = txtDBUser.Text
oCompany.DbPassword = txtDBPass.Text
'Me.Show() ' shows the form while it's loaded...
'Create a list of companies...
Try
oRecordSet = oCompany.GetCompanyList ' get the company list
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
oCompany.GetLastError(lErrCode, sErrMsg)
If lErrCode <> 0 Then
MsgBox(sErrMsg)
Else
Do Until oRecordSet.EoF = True
cmbCompany.Items.Add(oRecordSet.Fields.Item(0).Value)
oRecordSet.MoveNext()
Loop
'Disable Controls
cmdGetCompanyList.Enabled = False
cmbDBType.Enabled = False
'Enable Controls
txtUSer.Enabled = True
txtPassword.Enabled = True
cmdConnect.Enabled = True
cmbCompany.Enabled = True
End If
'Select the first company as default
If cmbCompany.Items.Count > 0 Then
cmbCompany.SelectedIndex = 0
Else
MsgBox("There was no Database Found...", , "Database not found...")
End ' Terminate Application...
End If
If oCompany.Connected Then ' if already connected
Me.Text = Me.Text & ": Connected"
' Remove the following 2 remark lines if you want to try to connect automatically
'Else
'Connect()
End If
End Sub
End Class
*********************************FIN DE CÓDIGO*********************************************************************
****************************************************************************************************************************
Les agradeceria inmensamente si pueden ayudarme en este tema.
Saludos cordiales a todos.
Marlo Chena
Tag: SAPbobsCOM - SAPbobsCOM.Users - SAPbobsCOM.Recordset - SAPbobsCOM.UserPermissionTree - SAPbobsCOM.Company