Have you ever done an import program into SBO objects from any source file, that after you have finished and implemented it, the user would asked whether you can add some more fields into the imported objects? remove this, change the field links ?
You will end up modifying your add on just to support that changes ?
Usually the add on is hardcoded to assign the source field into SBO field.
Don’t you think it will be nice if we could just have a setting kept somewhere that mapped all those source fields against the respective SBO object properties, PLUS the ability to add/remove the fields ?
It made me look for a way to achieve that functionality.
Keeping the mapping and reading all the fields from the mapping should not be difficult to handle, we can save it in UDT, or even a text file.
In order to map, I will need to know what are the fields exposed by DI API.
So, my first problem is ‘how do I get all the fields exposed by DI API?’
Using System.Reflection, we can get all the Objects, Properties, Methods, Enums from our interop.SAPbobsCOM.dll
The sample code below will retrieve all the accessible properties of Documents object.
Imports System.Reflection . . . Dim oAsm As Assembly =System.Reflection.Assembly.LoadFrom(My.Application.Info.DirectoryPath & "\Interop.SAPbobsCOM.dll") Dim oType As Type = oAsm.GetType("SAPbobsCOM.Documents") If Not oType Is Nothing Then Dim oProps() As PropertyInfo = oType.GetProperties() For Each oProp As PropertyInfo In oProps If oProp.CanWrite And oProp.PropertyType.IsPublic Then System.Diagnostics.Debug.WriteLine(oProp.Name) End If Next End If
With that, I solved my first problem, I have my Source Fields and also I can assign it to SBO Object’s properties.
OK, now that I have the mapping, but How can I then assign the correct DI properties ?
I know that my Source Field ‘CustomerCode’ is assigned to SBO Field called ‘CardCode’
how do we know that the string ‘CardCode’ is oDoc.CardCode ?
You can use Select Case, but that would be a lot of case.. 🙂
wouldnt it be nice if we could use something like
oDoc.GetField("CardCode").Value = "CustomerCode" ?
BTW, the above does not works… 😛
On my next post I will try to achieve almost the same functionality as above.