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

DEVELOPERS FORUM - hyperlink to an MS Outlook email to take a document.

hassane - Wednesday, August 5, 2015 3:04 AM:

I'd like to be able to add a hyperlink to an MS Outlook email to take someone directly to a document.  For instance, I'd like to send an email to an engineer asking them to look at a particular section of a document, and have a link in the email so they can just click on the link and be taken to the document in Aras Innovator. 



Dave_Rollinson - Friday, August 21, 2015 5:54 AM:

Hassane

You can use an Action/Method that can be linked to different ItemTypes.

JavaScript example to copy the URL to the clipboard, so it can be copied into an email, would be:

var thisId = this.getID();
var thisType = this.getType();
var basePath = window.location.pathname.split('/')[1];
var linkUrl = window.location.protocol + "//" +  window.location.host + "/" + basePath;
linkUrl += "?StartItem=" + thisType + ":" + thisId;
if (clipboardData && clipboardData.setData("Text",linkUrl)) {
    top.aras.AlertSuccess("Item URL copied to clipboard.");
}
return this;



Peter Borsje - Friday, August 21, 2015 9:13 AM:

 

//debugger;

// MailTo Actions Handler

//

// Called directly from an Action

//

// or called from an HTML field on a form.

// in this case this method must be added the "onLoad" Form Event

 

//

// opens the local email client

// 

// functions in this module query Innovator for email addresses 

// and item links (URL) information etc.

//

 

// ====== SAMPLE - HTML field Code ==== 

//

// On the from create an html field. Then cut and paste this 

// HTML- code to this link. (remove the comment caracters after pasting !)

//============================================================

/*  -- HTML-Code to run the mailTo function form an html field on a form

<script>

function openMail() {

  var thisItem = document.thisItem;

 

   top.openMailClientWithURL(thisItem);

 

}

</script>

 

<a id="mailto_action" href="BLOCKED SCRIPTopenMail()" ><img src="../images/icons/16x16/16x16_emailMessage.gif" border="0" alt="Open"><font color=#0000ff> Update Notification (mail with local email client)</a></td></tr></table></fieldset></span>

 --  end of HTML-code   -- */

 

//============================================================

//var inn = item.getInnovator();

 

top.openMailClientWithURL = function (thisItem) {

 

 

 

var href_link = 'mailto:${mailto}?subject=${subject}&body=${body}';

 

var thisItemType = thisItem.getAttribute("type","");

var thisItemNumber = thisItem.getProperty("item_number","");

var thisItemName =thisItem.getProperty("name","");

var thisItemRev = thisItem.getProperty("major_rev","");

 

//var rtnText = MailTo_Action_GetBlankSendToAddresses();

// BEGIN 0021214: owned_by email adres gebruiken bij 'email url'

// var rtnText = MailTo_Action_GetSendToAddressesOfItemIdentity(thisItem,"created_by_id");

var rtnText = MailTo_Action_GetSendToAddressesOfItemIdentity(thisItem,"owned_by_id");

//END 0021214: owned_by email adres gebruiken bij 'email url'

 

href_link = href_link.replace("${mailto}", rtnText);

 

rtnText = MailTo_Action_EmailSubject(thisItemType,thisItem);

href_link = href_link.replace("${subject}", rtnText);

 

rtnText = MailTo_Action_EmailBody(thisItemType,thisItem);

href_link = href_link.replace("${body}", rtnText);

 

//Replace special HTML characters rtnText = rtnText.replace("&","%26"); 

rtnText = rtnText.replace("=","%3D"); 

rtnText = rtnText.replace("?","%3F"); 

href_link = href_link.replace("${subject}", rtnText); 

rtnText = MailTo_Action_EmailBody(thisItemType,thisItem); 

//Repeat for body 

rtnText = rtnText.replace("&","%26"); 

rtnText = rtnText.replace("=","%3D"); 

rtnText = rtnText.replace("?","%3F"); 

href_link = href_link.replace("${body}", rtnText);

var win = window.open(href_link);

};

 

//================== Handler Functions ==============================

MailTo_Action_GetBlankSendToAddresses = function ()

{

  return "";

};

var sendToAliasIds = "";

 

//==============

MailTo_Action_GetSendToAddressesOfItemIdentity = function (thisItem, identity_property_name)

{

  // the property defined by 'identity_property_name' must be available for this item !!!

  // i.e.  "managed_by_id" or "owned_by_id" or "created_by_id"

  var identityId = thisItem.getProperty(identity_property_name,"");

  if (typeof(identityId) == "undefined" || identityId === "") {

    return "";  // empty

  }

 

  switch (identity_property_name)

  {

    case "created_by_id":

    case "locked_by_id":

case "modified_by_id":

      return getAllEmailAddressOfUser(identityId); // these are user id (not identities)

 

    default: 

      return getAllEmailAddressesOfIdentity(identityId, ";");

  }

  return "";

};

 

//==============

MailTo_Action_EmailSubject = function (thisItemType,thisItem)

{

  var subject = 'URL to ARAS Item: ';

  if (thisItemType.indexOf("Document") >=0 || thisItemType === "Part") {

subject += thisItem.getProperty("item_number","") + '-' + thisItem.getProperty("name","") + ' Rev:' + thisItem.getProperty("major_rev","");

  }

  else {

subject += thisItem.getProperty("keyed_name","");

  }

  return subject;

};

 

//==============

MailTo_Action_EmailBody = function (thisItemType,thisItem)

{

  var bodyText = 'Goedendag,%0A%0A';

  //## use text from resources , if text needs to be localized to multiple languages

  bodyText += 'Onderstaand data item is ter informatie naar u verzonden. Klik op de link om de details te bekijken.%0A%0A%0A';

  bodyText += 'ALGEMEEN %0A'; 

  bodyText += '========================================================= %0A';   

  bodyText += 'Item Nummer: ' + thisItem.getProperty("item_number","") + '%0A';

  bodyText += 'Item Naam: ' + thisItem.getProperty("name","") + '%0A';

  bodyText += 'Item Type: ' + thisItemType + '%0A';

  if (thisItemType === "cof_Execution notification") {  

  }

  else { 

 bodyText += '%0A%0A';

 bodyText += 'LAATSTE VERSIE %0A'; 

 bodyText += '========================================================= %0A'; 

 bodyText += BuildURL_toItem(thisItemType,thisItem.getProperty("id",""))  + ':current' + '%0A%0A%0A';    

 bodyText += 'SPECIFIEKE VERSIE %0A'; 

 bodyText += '========================================================= %0A';  

  }   

  if (thisItemType.indexOf("Document") >=0 || thisItemType === "Part") {

    bodyText += 'Item: ' + thisItem.getProperty("keyed_name","") + '%0A';

    bodyText += 'Item Status: ' + thisItem.getProperty("current_state_label","") + '%0A';

    bodyText += 'Item Rev: ' + thisItem.getProperty("major_rev","") + '%0A';

bodyText += 'Item Gen: ' + thisItem.getProperty("generation","") + '%0A';

  }

  else {

    bodyText += 'Item: ' + thisItem.getProperty("keyed_name","") + '%0A';

    bodyText += 'Item Status: ' + thisItem.getProperty("current_state_label","") + '%0A';

bodyText += 'Item Rev: ' + thisItem.getProperty("generation","") + '%0A';

    bodyText += 'Item Classificatie: ' + thisItem.getProperty("classification","") + '%0A';

  }

  bodyText += BuildURL_toItem(thisItemType,thisItem.getProperty("id","")) + '%0A';

  bodyText += '%0A%0A';

  bodyText += 'Indien de database niet automatisch opent dient u de volgende database te kiezen: ' + top.aras.getDatabase();

  bodyText += '%0A%0A';

 

  bodyText += 'Vriendelijke groet,' + '%0A';

  bodyText += 'Cofely Energy en Infra bv ' + '%0A';

 

  return bodyText;

};

 

BuildURL_toItem = function (thisItemType,thisItemId) {

  var serverUrl = top.aras.getServerURL();

  var pos = serverUrl.indexOf("/Server");

  var innovatorBaseUrl = serverUrl.substring(0,pos);

  var url = innovatorBaseUrl+'/Client/default.aspx?StartItem=' + thisItemType + ':' + thisItemId;

  url = url.replace(" ", "%25%32%30"); // replace space with %20 to get a valid href link in outlook

  return url;

};

 

function getAliasMembers (identityId, sepChar) {

 

  var aml = new Array();

    aml.push("<AML>");

    aml.push("<Item type='Identity' select='is_alias' action='GetItemRepeatConfig' id='"+ identityId +"'>");

    aml.push("<Relationships>");

aml.push("<Item type='Member' select='related_id,is_alias,keyed_name' repeatProp='related_id' repeatTimes='100'></Item>");

aml.push("</Relationships>");

    aml.push("</Item>");

    aml.push("</AML>");

    var amlstring = aml.join("");

    var allMembers = inn.applyAML(amlstring);

    if(allMembers.isError()){

        return; 

    }

 

// filter nested member list for uniek identities which are alias.

    aliasMembers = allMembers.getItemsByXPath("//Item[./is_alias='1'][@type='Identity'][not(@id=preceding::Item/@id)]");

 

    return aliasMembers;

 

}

 

function getAllEmailAddressOfUser(UserId) {

  // query enabled users

  var qry = new Item("User","get");

  qry.setID(UserId);

  qry.setProperty("logon_enabled","1");

  qry.setAttribute("select","login_name,email,logon_enabled");

  qry = qry.apply();

 

  if (qry.isError()) {return "";}

  else {

    return qry.getItemByIndex(0).getProperty("email","");

  }

}

 

function getAllEmailAddressesOfIdentity(topIdentityId, sepChar) {

 

  var aliasMembers = getAliasMembers (topIdentityId,",");  

  var rtn = "";   //return sendToAliasIds;

 

  //loop through ids and find related user and create list with email addresses separated by 'sepChar'

  var aliasMembersCount = aliasMembers.getItemCount();  

  for (var idx=0; idx < aliasMembersCount; idx++) {

    var identity = aliasMembers.getItemByIndex(idx);

var identityId = identity.getID();

 

    // get email address for each aliasMember which can logon 

var aml = new Array();

aml.push("<AML>");

aml.push("<Item type='User' action='get' select='email,logon_enabled'>");

aml.push("<logon_enabled>1</logon_enabled>");

aml.push("<Relationships>");

aml.push("<Item type='Alias' action='get' select='id' >");

aml.push("<related_id>"+ identityId +"</related_id>");

aml.push("</Item>");

aml.push("</Relationships>");

aml.push("</Item>");

aml.push("</AML>");

var amlstring=aml.join("");

var allUsers = inn.applyAML(amlstring);

 

   // get user details   

   if ( ! allUsers.isError() ) {

var thisUser = allUsers.getItemByIndex(0); // can have only 1 user per alias identity, take first one  

var thisUserEmail = thisUser.getProperty("email","");

if (thisUserEmail !== "") {

    if (rtn === "") {

 rtn += thisUserEmail;  

  } 

  else {

    rtn += sepChar + thisUserEmail;  

  }

}

   }

 

  } //end for idx (aliasMembersCount)

 

 

 return rtn;

}

 

// ======= MAIN ============   

var inn = top.aras.newIOMInnovator();

 

if (top.openMailClientWithURL) {

  var item = this;

  //var inn = this.getInnovator();

  var thisId = this.getID();

  var thisType = this.getAttribute("type","");

 

  // retrieve Item data

  var thisItem = top.aras.newIOMItem(thisType,"get");

  thisItem.setID(thisId);

  thisItem.setAttribute("select","item_number,name,major_rev,generation,classification,state,current_state_label, keyed_name,created_by_id,locked_by_id,owned_by_id,managed_by_id,team_id");

  thisItem = thisItem.apply();

  top.openMailClientWithURL(thisItem);

}

return;