Welcome Notes

Welcome Viewers

15 March 2018

Creating a Resource Master in SAP B1 via SDK

Dear Esteemed Readers,

Today, we embark on a journey through the intricate process of creating a Resource Master within SAP Business One using the Software Development Kit (SDK). Resource Masters form the backbone of efficient management within the SAP B1 ecosystem, enabling seamless tracking and utilization of vital organizational assets.



  Public Function AddResourceMaster(ByVal strVisCode As String, ByVal strResName As String, ByVal strResWarehouse As String) As Boolean
    Dim oCompanyService As SAPbobsCOM.CompanyService = Nothing
    Dim oResourceService As SAPbobsCOM.ResourcesService = Nothing
    Dim oResource As SAPbobsCOM.Resource = Nothing
    Dim oResWhs As SAPbobsCOM.ResourceWarehouse = Nothing
    Dim oResParamters As SAPbobsCOM.ResourceParams = Nothing

    Try
        oCompanyService = oApplication.SAPCompany.GetCompanyService
        oResourceService = oCompanyService.GetBusinessService(SAPbobsCOM.ServiceTypes.ResourcesService)
        oResource = oCompanyService.GetDataInterface(SAPbobsCOM.ResourcesServiceDataInterfaces.rsdiResource)
        
        ' Assign values to Resource properties
        oResource.VisCode = strVisCode
        oResource.Name = strResName
        
        ' Add Resource Warehouse
        oResWhs = oResource.Warehouses.Add
        oResWhs.Warehouse = strResWarehouse
        
        ' Add Resource using Service
        oResParamters = oResourceService.Add(oResource)
        
        Return True
    Catch ex As Exception
        ' Log or handle the exception accordingly
        ' Logging or displaying error messages for debugging purposes
        Return False
    Finally
        ' Properly dispose of resources
        If oResParamters IsNot Nothing Then oResParamters = Nothing
        If oResWhs IsNot Nothing Then oResWhs = Nothing
        If oResource IsNot Nothing Then oResource = Nothing
        If oResourceService IsNot Nothing Then oResourceService = Nothing
        If oCompanyService IsNot Nothing Then oCompanyService = Nothing
    End Try
End Function