Outlook Add-in argument exception on body.getAsync() method - javascript

According to https://dev.outlook.com/reference/add-ins/Body.html:
The GetAsync() method takes in 3 parameters. The first one is the Coercion Type which according to their documentation is a string value. The other two parameters for GetAsync are options and callback which are optional.
My code: var body = item.body.getAsync("html");
which gives this exception:
Exception details: outlook-web-16.00.js:formatted:5873 Uncaught Error: Sys.ArgumentTypeException: Object cannot be converted to the required type.
Am I not using the getAsync() method correctly? Most of the example code I've found online are using the callback parameter as well but if the options and callback parameters are optional and I only really need to get the contents of the email body as html, shouldn't this work?
P.S. This isn't an API versioning issue. I am definitely on 1.3 and body.getAsync does not return undefined.

Am I not using the getAsync() method correctly? Most of the example code I've found online are using the callback parameter as well but if the options and callback parameters are optional and I only really need to get the contents of the email body as html, shouldn't this work?
Since this method is a asynchronous, to get the result we have to use the callback. This sample should work:
Office.context.mailbox.item.body.getAsync("html", processHtmlBody);
function processHtmlBody(asyncResult) {
console.log(asyncResult.value)
}
This is a thread discussing getting the return value from asynchronous function using JavaScript.

Related

How to document javascript callback parameters with Sphinx?

I've been using the Sphinx documentation generator to document my javascript framework, however i'm not sure how i should go about documenting the parameters my callback functions get, for example
.. js:function:: execute(event, callback)
:param object event: The event object
:param function callback: the handler
:returns: a Promise
In the previous example callback is called with a request and reply parameter, however looking at the sphinx documentation for the javascript domain does not specify how i should go about documenting this.
What's the correct way?
http://www.sphinx-doc.org/en/stable/domains.html?highlight=js%20domain#the-javascript-domain

Using apply on Stripe Node.js library functions

In my Node.js application I'm trying to use apply to make a function call in the Stripe library since the access token parameter is optional. However, I'm getting a type error.
var args = [data];
if(accessToken) {
args.push(accessToken);
}
args.push(function(err, customer) {
...
});
stripe.customers.create.apply(this, args);
Uncaught TypeError: Cannot call method 'createUrlData' of undefined
at /home/codio/workspace/node_modules/stripe/lib/StripeMethod.js:33:24
I believe this a result of using strict mode but let me know if this is expected behavior. I'm using version 2.8.0 of the Stripe Node.js library.
Likely your this is undefined, and apply sets the context (what this is) in the called function. Under normal circumstances, the called function's this would be stripe.customers, so try:
stripe.customers.create.apply(stripe.customers, args);

Why does the Flickr API not let me name my own callback function for a JSONP request? Am I viewing this right?

It appears that when I use my own callback function via JSONP, Flickr wraps the JSON with its own function name called jsonFlickrFeed. And if I type the url/src directly on the browser, I do see that it's indeed wrapped.
Does this mean I'm supposed to name my function to jsonFlickrFeed? I thought when using JSONP, we get to name our own functions?
P.S. I've browsed the site for answers, but I couldn't find any direct answer. The only answer I found was that someone did use jsonFlickrFeed as the callback function name; however, being forced to use the name is what I want clarification on.
I'm also using javascript without jquery.
If you read the Flickr documentation under the callback section it says if you want to specify the callback you need to set jsoncallback to the value you want. They do not follow the pattern of "callback" like most sites use.
Callback Function
If you just want the raw JSON, with no function wrapper, add the
parameter nojsoncallback with a value of 1 to your request.
To define your own callback function name, add the parameter
jsoncallback with your desired name as the value.
nojsoncallback=1 -> {...}
jsoncallback=wooYay -> wooYay({...});
http://api.flickr.com/services/feeds/photos_public.gne?tags=cat+pic+%22&tagmode=any&format=json&jsoncallback=xxx

How to get value of property in javascript object?

I have an object which has status property. But I can't get the value of this property. Here is my code sample:
console.log("Resource.query()");
console.log(Resource.query());
console.log("Resource.query().status");
console.log(Resource.query().status);
Here is Chrome console:
As you see Resource.query().status returns undefined while Resource.query() returns the object. My question is how can I get the value of status ?
Thanks in advance.
query() is run asynchronously as noted in the tutorial (emphasis added):
$scope.phones = Phone.query();
This is a simple statement that we want to query for all phones. An important thing to notice in the code above is that we don't pass any callback functions when invoking methods of our Phone service. Although it looks as if the result were returned synchronously, that is not the case at all. What is returned synchronously is a "future" — an object, which will be filled with data when the XHR response returns. Because of the data-binding in Angular, we can use this future and bind it to our template. Then, when the data arrives, the view will automatically update.
try this:
Resource.query()[0].status

JSONP function call issue

i set up a webservice thats cross domain and needs to be contacted via json with padding
on a simple jquery codeline like this, i am successfull getting back json data.
$.getJSON("http://server/series/hist?jsonp=?", function(data){
console.log(data);
});
the webservice, will wrap the result in a function, whenever "jsonp" exists within in the url.
for those cases i used a default function name like:
myfunction({"a":1})
jquery helps me out here, and trys to call the function, that isnt existing ("myfunction()"). what i am trying to achieve instead is a simple call of the callback function (see above), to handle the data locally.
can you point me in the right direction?
thank you
I'm not quite sure what your problem actually is, but:
Interpretation 1
Assuming that by "locally" you mean "without using a callback":
That is impossible. JSON-P cannot work synchronously as it depends on the addition of a <script> element (which won't be processed until the current function has finished executing).
Interpretation 2
Assuming that by that isnt existing ("myfunction()") you mean "Your webservice always uses the function name myfunction:
Fix the webservice. jsonp=? means "Randomly generate a function name and pass it as the jsonp parameter.
The webservice must use that parameter to determine the function name used, and not use a fixed value such as myfunction.
Interpretation 3
You don't want to use JSON-P as the input, but to call your anonymous function directly.
You can't. It isn't stored anywhere you can access it. You have to rewrite your code so it isn't passed directly to getJSON:
function myFunction(data){
console.log(data);
}
$.getJSON("http://server/series/hist?jsonp=?", myfunction);
myfunction({"a":1})

Categories