This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Outlook, VBscript and M-Files handler

Former Member
Former Member
Hello,

I need some help please. I need to know how to handle Outlook from M-Files handler '' for my users, clearly i need to generate a task in outlook.
I try it out from M-Files, direct from Windows in many maners, and it works fine. But not from M-Files directly, for example i dont get the namespace.
Can someone help me please? Here, The code that i have been used:
Const olTaskItem = 3
wstartDate = Now + 1
wdueDate = Now + 30

Set OutlookApp = CreateObject("Outlook.Application")
Set oItems = OutlookApp.CreateItem(olTaskItem)

With oItems
.Subject = "Ma troisième tache"
.StartDate = wstartDate
.DueDate = wdueDate
.Body = "Mon message Mon message Mon message Mon message"
.Categories = "M-Files"
.Save
End With

Set oItems = Nothing
Set OutlookApp = Nothing
  • Former Member
    Former Member
    :) Allright.
    Thanks the new 9.0 version and his capabilities - UI Extensibility Framework - I solve my problem. The events logic in the UI give me the right answer.

    UI Extensibility is very very good! Thanks MFiles!
  • Jerome,

    We are glad to hear.

    I think you are one of the first who have accessed Office objects from UI Ext. application. Thanks for pointing out this possibility.

    Br,
    - Ari
  • Former Member
    Former Member
    Perhaps there should be a separate section in the forum for the UI Framework. What do others think?

  • :) Allright.
    Thanks the new 9.0 version and his capabilities - UI Extensibility Framework - I solve my problem. The events logic in the UI give me the right answer.

    UI Extensibility is very very good! Thanks MFiles!


    Hi Jerome,

    Could you share the UI Extensibility Framework usage, how to build it and deploy it? as there is no sample yet about this UI Extensibility Framework.

    Thanks,
    Andri
  • Former Member
    Former Member
    Hi!
    I was gone few days. Allright, I resume all what I have try with the UI. I take this on the blog in two hours.
  • Former Member
    Former Member
    (at first, sorry for my bad english...)
    I have two samples that i use with MS Office and our new UI Extended. At first, ensure that you have the good rights on your MS Windows side.
    The first sample is for the ShellUI and I create Menu commands in the ContextMenu and in the Taskpane. This commands (if activated) create an simple Excel Book and an simple Outlook Task.

    function OnNewShellUI( shellUI )
    {
    // Return event handlers as a closure.
    return {
    OnNewShellFrame: function( shellFrame ) {
    // Handle the OnNewShellFrame event of ShellUI.
    return {
    // OnStarted of the NewShellFrame
    OnStarted: function() {
    // Create menus only if a TaskPane is available. I avoid so the Popup windows case.
    if (shellFrame.TaskPane.Available) {
    // Declare sample Menu command
    var commandId = shellFrame.Commands.CreateCustomCommand( "~TEST Outlook~" );
    // Menu command added to the context Menu of the NewShellFrame.
    // See the UI Help for the many options...
    shellFrame.Commands.AddCustomCommandToMenu(commandId, MenuLocation_ContextMenu_BeforeWindowsCommands, 0 );
    // Menu command added to the TaskPane of the NewShellFrame
    // See the UI Help for the many options...
    shellFrame.TaskPane.AddCustomCommandToGroup( commandId, TaskPaneGroup_ViewAndModify, 0 );
    // Add custom command handler on your Menu command.
    shellFrame.Commands.Events.OnCustomCommand = function( activatedCommandId ) {
    // If the activated menucommand is my command
    if( activatedCommandId == commandId )
    {
    // Sample 1: create an Excel Book
    var Excel, Book;
    Excel = new ActiveXObject("Excel.Application");
    Excel.Visible = true;
    Book = Excel.Workbooks.Add()
    Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
    Book.SaveAs("C:\TEST.XLS");
    Excel.Application.Quit();

    // Sample 2: create an Outlook Task
    var Outlook;
    Outlook = new ActiveXObject("Outlook.Application");
    var objNS = Outlook.Session
    // Here 'personne' is my outlook profile name - Take your own...
    objNS.Logon ("personne", "", 0, 1)
    // create Outlook Task with some informations
    var oItem = Outlook.CreateItem(3);
    oItem.Subject = "tache 4";
    oItem.Body = "titititi titit iti tititi tititit iti";
    oItem.Categories = "M-Files";
    oItem.Save();
    }
    }
    }
    }
    };
    }
    };
    }


    In the next hour, I post an sample with the VaultUI that is more interresting for Vault Object manipulation.

    I hope you understand my horrible english. See you later...
  • Former Member
    Former Member
    Here a second sample JScript for the VaultUI. In the example, there is a Vault object with the name 'To Do'. Each To Do Vault Object has a relation to one unique Outlook Task.
    We will use the following VaultUI Handler to catch the operations on the vault object:
    OnPropertiesOfObjectVersionSet for modifying,
    OnObjectCreated for creating,
    OnDestroyObject before the vault object will be destroyed.


    function OnNewVaultUI( vaultUI ) {
    return {
    OnNewVaultEntry: function() {
    // Event for modify Vault Objects
    vaultUI.vaultEntry.Events.OnPropertiesOfObjectVersionSet = function( objectVersion ) {
    var oObjectVersion = objectVersion;
    // Proof the class for the 'To Do' Vault Object
    if ( oObjectVersion.Class == 31 ) {
    // Call treatment with argument for modify a outlook task
    otlTaskManager ("M", vaultUI, objectVersion);
    }
    }
    // Event for create Vault Objects
    vaultUI.vaultEntry.Events.OnObjectCreated = function( objectVersion ) {
    var oObjectVersion = objectVersion;
    // Proof the class for the 'To Do' Vault Object
    if ( oObjectVersion.Class == 31 ) {
    // Call treatment with argument for create a outlook task
    otlTaskManager ("C", vaultUI, objectVersion);
    }
    }
    // Event before destroy the 'To Do' Vault Object
    vaultUI.vaultEntry.Events.OnDestroyObject = function( objID ) {
    // This is called before the object is destroyed.
    return {
    OnSuccess: function() {
    // Proof the Type for the 'To Do' Vault Object
    if ( objID.Type == 129 ) {
    // Delete the correspondant Outlook Task. Think: I use the Outlook Task property 'BillingInformation' for the unicity and for the relation between the Vault Object and the Outlook Task. So it allows to modify the Subject property of the Outlook Task.
    Outlook = new ActiveXObject("Outlook.Application");
    var objNS = Outlook.Session;
    objNS.Logon ("personne", "", 0, 1);
    var olFolderTasks = 13
    var objTasks = objNS.GetDefaultFolder(olFolderTasks);
    var wSearchStr;
    wSearchStr = "[BillingInformation] = '"+ objID.ID +"'";
    oItem = objTasks.Items.Find(wSearchStr);
    if (oItem != undefined){
    oItem.Delete();
    }
    }
    },
    OnError: function( errorCode, errorMessage, errorStack ) {
    MFiles.ThrowError( "Something went wrong..." );
    },
    Finally: function() {
    // nothing to do
    }
    }
    }
    }
    }
    }

    // Function to Modify or to Create an Outlook Task that have a relation to one Vault Object
    function otlTaskManager (actionType, vaultUI, objectVersion) {
    var oObjectVersion = objectVersion;
    var oVault = vaultUI.Vault;
    var wActionType = actionType;

    // Get the version and the properties of the Vault object
    var oObjVerAndProperties = oVault.ObjectOperations.GetLatestObjectVersionAndProperties(oObjectVersion.ObjVer.ObjID, 1);
    var oPropValues = oObjVerAndProperties.Properties;

    // Over all properties of the Vault Object: build the Outlook Task properties
    var j = 1;
    while (j
    var oPropvalue = oPropValues.Item(j);
    var oPropDef = oVault.PropertyDefOperations.GetPropertyDef(oPropvalue.PropertyDef);
    switch (oPropvalue.PropertyDef) {
    case 0:
    var wSubject = oPropvalue.GetValueAsLocalizedText();
    break;
    case 20:
    var wStartdate = oPropvalue.GetValueAsLocalizedText();
    break;
    case 1109:
    var wDueDate = oPropvalue.GetValueAsLocalizedText();
    break;
    case 1111:
    var wState = oPropvalue.GetValueAsLocalizedText();
    break;
    case 1113:
    var wPriority = oPropvalue.GetValueAsLocalizedText();
    break;
    case 1027:
    var wBody = oPropvalue.GetValueAsLocalizedText();
    break;
    case 1095:
    var wtypInter = oPropvalue.GetValueAsLocalizedText();
    break;
    case 1097:
    var wdetInter = oPropvalue.GetValueAsLocalizedText();
    break;
    }
    j++;
    }

    // Create the Outlook Application
    Outlook = new ActiveXObject("Outlook.Application");
    var objNS = Outlook.Session;
    // Here 'personne' is my outlook profile name - Take your own...
    objNS.Logon ("personne", "", 0, 1);

    // Create or modify an Outlook Task
    var olFolderTasks = 13
    var olTaskComplete = 2;
    var olTaskDeferred = 4;
    var olTaskInProgress = 1;
    var olTaskNotStarted = 0;
    var olTaskWaiting = 3;
    var olImportanceHigh = 2;
    var olImportanceLow = 0;
    var olImportanceNormal = 1;
    var oItem ;
    switch (wActionType) {
    case "C":
    // Create one Outlook TaskItem
    oItem = Outlook.CreateItem(3);
    break;
    case "M":
    // Modify one Outlook TaskItem
    // Get the Outlook TaskFolder
    var objTasks = objNS.GetDefaultFolder(olFolderTasks);
    // Search the the Outlook Task Item with the ID oh the Vault Object. The Outlook Task property 'BillingInformation' is needed for the relation to the Vault Object
    var wSearchStr = "[BillingInformation] = '"+ oObjectVersion.ObjVer.ID +"'";
    oItem = objTasks.Items.Find(wSearchStr);
    if (oItem == undefined){
    vaultUI.ShowMessage ( "Task not found, will be recreated." );
    oItem = Outlook.CreateItem(3);
    }
    break;
    default:
    // By wrong argument: create Outlook task item
    oItem = Outlook.CreateItem(3);
    }
    // Fill the outlook Task Item
    oItem.Subject = wSubject;
    oItem.Body = wtypInter + "\n" + wdetInter + "\n" + wBody;
    oItem.Categories = "M-Files";
    oItem.StartDate = wStartdate;
    oItem.DueDate = wDueDate;
    switch (wState) {
    case "Non commencée":
    oItem.Status = olTaskNotStarted;
    break;
    case "En cours":
    oItem.Status = olTaskInProgress;
    break;
    case "Terminée":
    oItem.Status = olTaskComplete;
    break;
    case "Différée":
    oItem.Status = olTaskDeferred;
    break;
    case "En attente":
    oItem.Status = olTaskWaiting;
    break;
    default:
    oItem.Status = olTaskNotStarted;
    break;
    }
    switch (wPriority) {
    case "Faible":
    oItem.Importance = olImportanceLow;
    break;
    case "Normale":
    oItem.Importance = olImportanceNormal;
    break;
    case "Haute":
    oItem.Importance = olImportanceHigh;
    break;
    default:
    oItem.Importance = olImportanceNormal;
    break;
    }
    oItem.BillingInformation = oObjectVersion.ObjVer.ID;
    oItem.Save();
    }


    :) Have fun
  • Former Member
    Former Member
    Another informations on the environment: Windows seven 64bits and outlook 2010.
  • Former Member
    Former Member
    For the deployment of the JScript on the localhost to test at first. Under
    ..\Client\Apps\\Sysapps\\

    Appdef.xml - The Guid of the application must be unique


    -
    B0573AE7-C62D-4266-A622-C13148B3CD6D
    internetAfaire
    Sample Application
    -
    -
    main.js





    Main.js
    See the code of the preview posts.
  • Former Member
    Former Member
    :) Hi!
    Instead OnNewShellFrame take OnNewNormalShellFrame and you dont need the 'if shellFrame.TaskPane.Available'.