You want to import data from a Microsoft Project file to a SAP transaction.

Microsoft offers an interface for the Office products, which you can address with the GuiXT Controls.

Please note that Microsoft Project must be installed on the respective PC in this case.

You can address the interface either via JavaScript (callJS command) or via a .NET extension (callVB command). We describe both possibilities below, each of which has advantages and disadvantages.

In this example, we want to import data from Microsoft Project to the SAP Project Builder (CJ20):


Import data from Microsoft project:

The InputScript will import all tasks from a .MPP file and puts the data into the SAP table.

In this example, we used the template "simple project plan" offered by MS Project. 

Using a JavaScript call:

Call the following InputScript, which in this example inserts all tasks from the MS Project file:  

CreateTable V[tasktable] taskname taskstart taskend
// Read tasks from MS Project file
callJS gettasks "C:\data\simple_project.mpp"  "tasktable"
Set V[k] 1
label nextrow
if not V[k>&V[tasktable.rowcount]]
  Set  cell[table,RCWBT-PIDEN,&V[k]] "&V[tasktable.taskname.&V[k]]"
  Set cell[table,RCWBT-STERM,&V[k]] "&V[tasktable.taskstart.&V[k]]"
  Set cell[table,RCWBT-ETERM,&V[k]]  "&V[tasktable.taskend.&V[k]]"
  Set V[k] "&V[k]" + 1
  goto nextrow
if V[r] 
  message "E: &V[r]" -statusline
  message "Tasks imported from MS Project" -statusline

The method "gettasks" must be present in the JavaScript library specified in the GuiXT profile and looks like this:


function gettasks(filename, outtab) {

    // Create MS Project connection and open the file
    var MS = guixt.CreateObject("MSProject.Application");

    // MS.Visible = true;

    var proj = MS.ActiveProject;

    // We want to go through all the elements in the list
    var tasks = new Enumerator(proj.Tasks);

    // This is the target list for GuiXT
    var tasksArray = [];

    while (tasks.atEnd() == false) {

        // Create a new task object
        var tstart = new Date(tasks.item().Start);
        var tend = new Date(tasks.item().Finish);

        // Convert to date formate DD.MM.YYYY
        tstart = tstart.getDay() + "." + tstart.getMonth()
            + "." + tstart.getFullYear();

        tend = tend.getDay() + "." + tend.getMonth()
            + "." + tend.getFullYear();

        var task = {
            "taskname": tasks.item().Name,
            "taskstart": tstart,
            "taskend": tend

        // Add the new task to our list

        // Get next element

    // When "createTab" is used in GuiXT, you can easily
    // put the data in JSON notation into the table
    guixt.Set(outtab, JSON.stringify(tasksArray));


Using a .NET library:

The InputScript from above just slightly changes: The JavaScript call is replaced by a call to the function in the guixt_office.dll file:

 // callJS gettasks "C:\data\simple_project.mpp"  "tasktable"
 callVB r = guixt_office.msproject.gettasks _ 
   filename:="C:\data\simple_project.mpp" _ 

The corresponding function "gettasks" in VB.NET:

''' <summary>
''' Get all task in a MS Project file
''' </summary>
''' <param name="filename">Path to the MS project file</param>
''' <param name="output">Name of GuiXT longtext variable </param>    ''' 
''' <returns>empty string if success, errortext otherwise</returns>
Public Function GetTasks(filename As String, output As String) As String

    Dim returnText As String = ""


        'Create the Application object to interact with MS project
        Dim projectApplication As Microsoft.Office.Interop.MSProject.Application =
            New Microsoft.Office.Interop.MSProject.Application()

        Dim mv As Object = System.Reflection.Missing.Value

        projectApplication.FileOpenEx(filename, mv, mv,
                                      mv, mv, mv, mv,
                                      mv, mv, mv, mv,
                                      mv, mv,
                                      mv, mv, mv)

        ' Get the active project in the file
        Dim project As Microsoft.Office.Interop.MSProject.Project _
            = projectApplication.ActiveProject

        ' Define a list to put the tasks into
        Dim tasks As ArrayList = New ArrayList

        ' Hint:
        ' We create a list containing rows of dictionary objects
        ' A dictionary stores key-value pairs
        ' We can convert this to JSON notation later

        For Each task As Microsoft.Office.Interop.MSProject.Task In project.Tasks

            If task IsNot Nothing Then

                ' Grab some of the information of this task and save it

                Dim td As New Dictionary(Of String, String)
                td.Item("taskname") = task.Name.ToString
                td.Item("taskstart") = task.Start.ToString
                td.Item("taskend") = task.Finish.ToString

            End If

        ' Convert the list of tasks to JSON format
        Dim serializer As New JavaScriptSerializer()
        Dim arrayJSON As String = serializer.Serialize(tasks)

        ' Save the data into a GuiXT table variable
        myguixt.SetVariable(output, arrayJSON)

        ' Hint: If you use createTable in GuiXT, you can use JSON 
        ' to exchange data. All rows are automatically updated by GuiXT

    Catch ex As Exception

        ' Something went wrong: Return the message to GuiXT
        ' so it can be shown on the SAP transaction
        ' e.g. file was not found
        returnText = ex.Message
    End Try

    Return returnText

End Function


Comparison between JavaScript and .NET

Using JavaScript is possible without much effort, but it has the following disadvantage: you have to figure out the methods you need and their parameters, and you have few tools or testing options available. You can therefore also create a .NET library, have tools such as code completion available there and can first test independently of GuiXT and the SAP transaction.

How to create your own .NET dll is described here:
Calling a VB.NET function

You can download the sample project and use it as a basis for your own developments or just use the compiled library.


Download the .NET project with source-code:

Download the stand-alone classlibrary:

JavaScript library:

Sample MS Project file:

Hint: You might need to "unblock" downloaded .dll files if you want to use them:
Go to file properties (right-click) and choose "unblock".

Components InputAssistant + Controls