setAsync returns success status but not inserting data in MAC installed outlook - outlook-addin

here I am implementing an email tracking system using image insertion , and i used 'Office.context.mailbox.item.body.setAsync' office API , everywhere it is working but not in installed MAC outlook though it returns 'success' in asyncResult.status.Please help me out.

Also, as a reference you can try the below mentioned code snippet:
var htmlData = '<img src=\"https://www.w3schools.com/css/paris.jpg\">';
Office.context.mailbox.item.body.setAsync(
htmlData,
{coercionType: "html"},
function (asyncResult) {
if (asyncResult.status == "failed") {
console.log("Action failed with error: " + asyncResult.error.message);
}
else {
console.log("Successfully set body text");
}
}
);

/* ReadWriteItem or ReadWriteMailbox */
/* Set body content */
Office.context.mailbox.item.body.setAsync(
'<img src=\"https://www.w3schools.com/css/paris.jpg\">',
{coercionType: "html"},
function (asyncResult) {
if (asyncResult.status == "failed") {
console.log("Action failed with error: " + asyncResult.error.message);
} else {
console.log("Successfully set body text");
}
});
I used above code and it worked in 15.40

Related

append hidden content to meeting body in outlook using office js

using my outlook add-in I need to add some hidden data (some metadata) to meeting body. I tried adding display:none style to html element but no luck. is there any way to achieve this?
below is my code to set body content
function addWorkspaceToItemBody(textToAppend) {
var d = $q.defer();
var item = Office.context.mailbox.item;
item.body.getTypeAsync(
function (result) {
if (result.status == Office.AsyncResultStatus.Failed){
write(result.error.message);
}
else {
// Successfully got the type of item body.
// Set data of the appropriate type in body.
if (result.value == Office.MailboxEnums.BodyType.Html) {
// Body is of HTML type.
// Specify HTML in the coercionType parameter
// of setSelectedDataAsync.
item.body.setSelectedDataAsync(
'<p style="display:none">'+textToAppend+'<\p>',
{ coercionType: Office.CoercionType.Html,
asyncContext: { var3: 1, var4: 2 } },
function (asyncResult) {
if (asyncResult.status ==
Office.AsyncResultStatus.Failed){
d.reject(asyncResult.error.message);
}
else {
d.resolve(asyncResult)
// Successfully set data in item body.
// Do whatever appropriate for your scenario,
// using the arguments var3 and var4 as applicable.
}
});
}
else {
// Body is of text type.
item.body.setSelectedDataAsync(
"",
{ coercionType: Office.CoercionType.Text,
asyncContext: { var3: 1, var4: 2 } },
function (asyncResult) {
if (asyncResult.status ==
Office.AsyncResultStatus.Failed){
d.reject(asyncResult.error.message);
}
else {
d.resolve(asyncResult)
// Successfully set data in item body.
// Do whatever appropriate for your scenario,
// using the arguments var3 and var4 as applicable.
}
});
}
}
});
return d.promise;
}
Below is an example to insert hidden content using the following code. The content is hidden in Outlook 2016, OWA, and Outlook for Android. It may still show up if the content is viewed as plain text in other email clients.
var content =
"<!--[if !mso 9]><!-->"+
'<div class="hidden" style="display:none;max-height:0px;overflow:hidden;">'+
"CONTENT HERE THAT YOU WANT TO HIDE"+
"</div>"+
"<!--<![endif]-->";
Office.context.mailbox.item.body.setSelectedDataAsync("Hello World! " + content, function (asyncResult) {
if (asyncResult.status == "failed") {
console.log("Action failed with error: " + asyncResult.error.message);
}
});
Source

Google App Script custom error on .withFailureHandler

I would like to throw a custom error in a function called with google.script.run from code.gs so I could display adequate information in a side bar. So far I've tested the following code with no luck:
code.gs
function UserException(type, text) {
this.type = type;
this.text = text;
//this.stack = (new Error()).stack;
}
UserException.prototype = Object.create(Error.prototype);
UserException.prototype.constructor = UserException;
function assignRangeToTechnician(technician)
{
if(technician!=null)
{
//some code
}else
throw new UserException("Error","Technician was not selected");
}
sidebar.html
...
<script>
function btnSelectTech()
{
google.script.run
.withSuccessHandler(rangeSelected)
.withFailureHandler(techniciansMessage)
.assignRangeToTechnician(document.getElementById('selectTechnician').value);
}
function techniciansMessage(Message)
{
var outputMessage = document.getElementById('message');
//here is where I log the Message value
google.script.run.myLog("In techniciansMessage() - Message: " + Message);
if (Message == null)
outputMessage.innerHTML = "<p style='color:red;'>Error occured</p>";
else
if (Message.type == "Error")
outputMessage.innerHTML = "<p style='color:red;'>" + Message.text + "</p>";
else if (Message.type == "Message")
outputMessage.innerHTML = "<p style='color:#f3f3f3;'>" + Message.text + "</p>";
}
</script>
...
When I run the code the .withFailureHandler is called but the Message doesn't hold the proper value. When I log that message I read "Error: " as a content of a 'Message' parameter.
Could you please help?
Thank you.
You may refer with this SO thread. Try adding an error parameter to your function. Example:
google.script.run.withFailureHandler(function (error) {
showError(error, 'getMe');
}).getMe();
Additional reference which might help: https://github.com/google/google-apps-script-samples/blob/master/translate/Sidebar.js.html

Parse Cloud Code query not getting executed

I have the below cloud code function and when I call this function from my OS X app, I get the success response as well. But none of the console log output messages inside the success and failure blocks of the query operation gets executed. Any ideas on where to look would be much appreciated.
Parse.Cloud.define("markAlertAsExpired", function(request, response) {
Parse.Cloud.useMasterKey();
var Alert = Parse.Object.extend("Alert");
var query = new Parse.Query(Alert);
query.get("vC6ppoxuqd", {
success: function(alertObj) {
// The object was retrieved successfully.
var status = alertObj.get("status");
console.log("RECEIVED OBJECT WITH STATUS:");
console.log(status);
if (status == "active") {
console.log("active");
markActiveAlertAsExpired(alertObj);
} else if (status == "inactive") {
console.log("inactive");
markInactiveAlertAsExpired(alertObj);
} else {
console.error("unknown_status");
}
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
console.error("alert_not_found");
response.error("alert_not_found");
}
});
response.success("available");
});
You need to wait for your queries to complete before calling response.success, the updated code below should work.
Parse.Cloud.define("markAlertAsExpired", function(request, response) {
Parse.Cloud.useMasterKey();
var Alert = Parse.Object.extend("Alert");
var query = new Parse.Query(Alert);
query.get("vC6ppoxuqd", {
success: function(alertObj) {
// The object was retrieved successfully.
var status = alertObj.get("status");
console.log("RECEIVED OBJECT WITH STATUS:");
console.log(status);
if (status == "active") {
console.log("active");
markActiveAlertAsExpired(alertObj);
} else if (status == "inactive") {
console.log("inactive");
markInactiveAlertAsExpired(alertObj);
} else {
console.error("unknown_status");
}
response.success("available");
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
console.error("alert_not_found");
response.error("alert_not_found");
}
});
});

webrtc: createAnswer works on chrome but fires an error with firefox

function createPeerConnection() {
try {
pc = new RTCPeerConnection(null, pc_constraints);
pc.onicecandidate = handleIceCandidate;
pc.onaddstream = handleRemoteStreamAdded;
pc.onremovestream = handleRemoteStreamRemoved;
console.log('Created RTCPeerConnnection');
} catch (e) {
console.log('Failed to create PeerConnection, exception: ' + e.message);
alert('Cannot create RTCPeerConnection object.');
return;
}
try {
// Reliable Data Channels not yet supported in Chrome
sendChannel = pc.createDataChannel("sendDataChannel",
{reliable: false});
sendChannel.onmessage = handleMessage;
trace('Created send data channel');
} catch (e) {
alert('Failed to create data channel. ' +
'You need Chrome M25 or later with RtpDataChannel enabled');
trace('createDataChannel() failed with exception: ' + e.message);
}
sendChannel.onopen = handleSendChannelStateChange;
sendChannel.onclose = handleSendChannelStateChange;
pc.ondatachannel = gotReceiveChannel;
}
function doAnswer() {
console.log('Sending answer to peer.');
pc.createAnswer(setLocalAndSendMessage, null, sdpConstraints);
}
I got error:
TypeError: Argument 2 of mozRTCPeerConnection.createAnswer is not an object.
The following code should work in Firefox:
function doAnswer() {
console.log('Sending answer to peer.');
pc.createAnswer(setLocalAndSendMessage, handleCreateAnswerError, sdpConstraints);
}
function setLocalAndSendMessage(sessionDescription) {
sessionDescription.sdp = preferOpus(sessionDescription.sdp);
pc.setLocalDescription(sessionDescription);
console.log('setLocalAndSendMessage sending message' , sessionDescription);
sendMessage(sessionDescription);
}
function handleCreateAnswerError(error) {
console.log('createAnswer() error: ', e);
}
The reason why this fails in Firefox can be found in the documentation for createAnswer. The issue is that Firefox won't let you pass null for the error handler. All this requires is that you write your own and then pass it into createAnswer. Don't pass null, you should actually be passing a function (object) to do something with the error.
Sorry for the late response, better late than never!
how about this? Its what the guys # xsockets use...
pc.createAnswer(setLocalAndSendMessage,function (ex) { self.onerror(ex); }, sdpConstraints);

Childbrowser terminates

Calling multiple function in a javascript to get Username/Emailaddress/Password. When everything is fine go to goForLogin() and open a chrildbrowser. I get en error (See below):
First my code:
function goForLogin(emailaddress, value){
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","http://dev.server.com/test/login",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("email=" + emailaddress + "&password=" + value);
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.status==200)
{
value = null;
window.plugins.childBrowser.showWebPage('http://dev.server.com');
} else {
alert("FAILED");
}
}
}
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present
modally an active controller .'
* First throw call stack: (0x154012 0x25fce7e 0x478721 0x479777 0x4797b7 0x6a68 0x67471 0x66c5e 0x67039 0x26106b0 0x1198035 0xd7f3f
0xd796f 0xfa734 0xf9f44 0xf9e1b 0x33be7e3 0x33be668 0x38f65c 0x2366
0x2295) libc++abi.dylib: terminate called throwing an exception (lldb)
Newest Cordova and Childbrowser, Xcode 4.4 versions.
I got it! Because of the xmlhttp.onreadystatechange statement the childBrowser is going to be open three times in this script. It is not allowed by apple - sorry, I forgot why - so I did a call back. It looks like this:
My JavaScript:
function some_function2(url, callback) {
var httpRequest; // create our XMLHttpRequest object
if (window.XMLHttpRequest) {
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// Internet Explorer is stupid
httpRequest = new
ActiveXObject("Microsoft.XMLHTTP");
}
httpRequest.onreadystatechange = function() {
// inline function to check the status
// of our request
// this is called on every state change
if (httpRequest.readyState === 4 &&
httpRequest.status === 200) {
callback.call(httpRequest.responseXML);
// call the callback function
}
};
httpRequest.open('POST', url, true);
httpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
httpRequest.send("email=test#test.com&password=1");
}
function call() {
// call the function
some_function2("http://dev.server.com/account/login/", function() {
console.log(this);
callChildBrowser();
});
console.log("this will run before the above callback");
}
function callChildBrowser(){
window.plugins.childBrowser.showWebPage('http://dev.server.com');
}
Finally in my html:
<button id="butten" onclick="call()">WORKS</button>