Replacement for active x object - javascript

I am working on developing Outlook appointment. I have a requirement where
I have to create a file and download it . When I open that file it has to open in outlook and create meeting request pop up without using active x . Is there any api developed by Microsoft. Its better if the snippet is from java script
Right now I am able to open pop up with Meeting request in Outlook from the web browser. I am able to do this by enabling Active x controls But it works in IE only. Moreover active x will not be supported by Microsoft in near future.
Current code
var outlookAppObj = new ActiveXObject("Outlook.Application");
var objNS = outlookAppObj.GetNameSpace("MAPI");
var theMailItemObj
=outlookAppObj.CreateItem(0);
theMailItemObj.display();

Your code above creates and displays a regular message. You can achieve the same result using a mailto: link.
For an appointment, create an ICS file and the user download it - Outlook will be happy to open it. the user can then click Save.

Prepare ics file as var finalAttachedData = "ATTACH;FMTTYE= application/vnd.openxmlformats-officedocument.wordprocessingml.document;ENCODING=BASE64;VALUE=BINARY;X-FILENAME=test.docx:"+base+"\n";
var icsMSG = ["BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\n" + finalAttachedData + "\nUID:me#google.com\nDTSTAMP:20120315T170000Z\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me#gmail.com\nORGANIZER;CN=Me:MAILTO::testmail\nDTSTART:" + Date.now() +"\nDTEND:" + Date.now() +"\nLOCATION:" + "hyd" + "\nSUMMARY:Our Meeting Office\nEND:VEVENT\nEND:VCALENDAR"];

Related

How to use Chrome profile in Selenium (selenium-webdriver) JavaScript

Since there doesn't seem to be a way to use an existing Chrome window, how do I use the Google account (and all settings and passwords) of the user in the window that Selenium opens? Selenium seems to open windows for itself, but without a Google account, which is an essential part to my program.
My program is very time sensitive, so it needs to be logged in to the websites it accesses automatically, and the program is going to be used by multiple users.
var webdriver = require("selenium-webdriver");
var chrome = require("selenium-webdriver/chrome");
var options = new chrome.Options();
options.addArguments("user-data-dir=C:\\Users\robert.car\\AppData\\Local\\Google\\Chrome\\User Data")
options.addArguments("profile-directory=Profile 1")
var driver = let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
user-data-dir considers profile as default , and you don't have to specify that . If its something else specify it through profile-directory argument
Step to create a profile:
open : chrome://version in address bar
copy the user dir folder completely to eg c:\tmp\newdir
open the copied user data (newdir) and search for folder called Default . This is the profile folder.
rename the Default folder as "Profile 1"
Now to use this :
options.addArguments("user-data-dir=c:\\tmp\\newdir")
options.addArguments("profile-directory=Profile 1")

add the current date to a pdf (when opened in browser)

I currently have a javaScript in a pdf that adds the current date once the document is opened in adobe.
function dateToday()
{
var date = new Date();
field = this.getField("todayDate");
field.value = date;
}
dateToday();
Now I want to upload this documents on a Sharepoint. But logically when I open the docs in the browser the javaScript is not triggered and the date is not updated (also when printing).
Is there any way I can change the script so it triggers when the pdf is opened in a browser?
Or how can I change the script so that it instead prints an error message when downloaded and opened in Adobe?
Thanks!!
We use Muhimbi PDF Converter for SharePoint On-Open functionality to add Dynamic Content(Current Date, User name, etc). You can find more details at https://blog.muhimbi.com/2011/04/applying-user-specific-watermarks-when.html
They also provide various watermarking facilities for details see http://support.muhimbi.com/entries/23730002-What-are-the-watermarking-facilities-of-the-PDF-Converter-for-SharePoint-

How to open ical event without downloading using Javascript?

I am trying to implement a function where users will be able to open appointments/meetings on performing some action. I found it can be done using ical.
var icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\nUID:me#google.com\nDTSTAMP:20120315T170000Z\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me#gmail.com\nORGANIZER;CN=Me:MAILTO::me#gmail.com\nDTSTART:" + msgData1 +"\nDTEND:" + msgData2 +"\nLOCATION:" + msgData3 + "\nSUMMARY:Our Meeting Office\nEND:VEVENT\nEND:VCALENDAR";
window.open( "data:text/calendar;charset=utf8," + escape(icsMSG));
But it is first downloading the ics file, and then only when a user clicks on the downloaded file, it will open the appointment. Instead of that, I want the appointment to be opened directly without downloading. Please help me with this.

Add attachment by url to Outlook mail

The context
There is a button on the homepage of each document set in a document library on a SharePoint Online environment. When the button is clicked, an Outlook window opens with the title and body set and all the files in the document set should be added as the attachments.
The code
Here's the code I have so far:
var olApp = new ActiveXObject("Outlook.Application");
var olNs = olApp.GetNameSpace("MAPI");
var olItem = olApp.CreateItem(0);
var signature = olItem.HTMLBody;
signature.Importance = 2;
olItem.To = "";
olItem.Cc = "";
olItem.Bcc = "";
olItem.Subject = "Pre filled title";
olItem.HTMLBody =
"<span style='font-size:11pt;'>" +
"<p>Pre filled body</p>" +
"</span>";
olItem.HTMLBody += signature;
olItem.Display();
olItem.GetInspector.WindowState = 2;
var docUrl = "https://path_to_site/Dossiers/13245_kort titel/New Microsoft Word Document.docx";
olItem.Attachments.Add(docUrl);
The Problem
When I run this code, an Outlook window opens with everything set correctly. But on the line where the attachment is added I get following very vague error message:
SCRIPT8: The operation failed.
I thought it could be the spaces in the url so I replaced them:
docUrl = docUrl.replace(/ /g, "%20");
Also didn't work (same error) and providing all parameters like this also didn't work:
olItem.Attachments.Add(docUrl, 1, 1, "NewDocument");
Passing a path to a local file (e.g. C:/folder/file.txt) or a publicly available url to an image does work. So my guess is it has something to do with permissions or security. Does anybody know how to solve this?
PS: I know using an ActiveX control is not the ideal way of working (browser limitations, security considerations, ...) but the situation is what it is and not in my power to change.
You cannot pass a url to MailItem.Attachments.Add in OOM (it does work in Redemption - I am its author - for RDOMail.Attachments.Add). Outlook Object Model only allows a fully qualified path to a local file or a pointer to another item (such as MailItem).

Auto Save a file in Firefox

I am trying to find a way where by we can auto save a file in Firefox using JS. The way I have done till yet using FireShot on a Windows Desktop:
var element = content.document.createElement("FireShotDataElement");
element.setAttribute("Entire", EntirePage);
element.setAttribute("Action", Action);
element.setAttribute("Key", Key);
element.setAttribute("BASE64Content", "");
element.setAttribute("Data", Data);
element.setAttribute("Document", content.document);
if (typeof(CapturedFrameId) != "undefined")
element.setAttribute("CapturedFrameId", CapturedFrameId);
content.document.documentElement.appendChild(element);
var evt = content.document.createEvent("Events");
evt.initEvent("capturePageEvt", true, false);
element.dispatchEvent(evt);
But the issue is that it opens a dialog box to confirm the local drive location details. Is there a way I can hard code the local drive storage location and auto save the file?
If you are creating a Firefox add-on then FileUtils and NetUtil.asyncCopy are your friends:
Components.utils.import("resource://gre/modules/FileUtils.jsm");
Components.utils.import("resource://gre/modules/NetUtil.jsm");
var TEST_DATA = "this is a test string";
var source = Components.classes["#mozilla.org/io/string-input-stream;1"].
createInstance(Components.interfaces.nsIStringInputStream);
source.setData(TEST_DATA, TEST_DATA.length);
var file = new FileUtils.File("c:\\foo\\bar.txt");
var sink = file.openSafeFileOutputStream(file, FileUtils.MODE_WRONLY |
FileUtils.MODE_CREATE);
NetUtil.asyncCopy(source, sink);
This will asynchronously write the string this is a test string into the file c:\foo\bar.txt. Note that NetUtil.asyncCopy closes both streams automatically, you don't need to do it. However, you might want to pass a function as third parameter to this method - it will be called when the write operation is finished.
See also: Code snippets, writing to a file
Every computer has a different file structure. But still, there is a way. You can save it to cookie / session, depends on how "permanent" your data wants to be.
Do not consider writing a physical file as it requires extra permission.

Categories

Resources