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
Parents
  • 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
Reply
  • 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
Children
No Data