QuerySchedule WebAPI function call - dynamics-crm

I am using Web API calls to Dynamics 365 to get result for function QuerySchedule. I have tried using this as a bound function as well. But none of them returns the expected result. Below is documentation on this:
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/queryschedule?view=dynamics-ce-odata-9
I have tried different resource id, different ways to specify the enum type in the call, fully qualified function name, etc but I always get error.
Following is my call:
https://mycrm.com/api/data/v9.0/QuerySchedule(ResourceId=#p1,Start=#p2,End=#p3,TimeCodes=#p4)?#p1=resourceguid&#p2=2019-01-05T09:27:39Z&#p3=2019-01-05T21:27:39Z&#p4=Available
The output is expected to be QueryScheduleResponse as mentioned in below link:
https://learn.microsoft.com/en-us/dynamics365/customer-engagement/web-api/queryscheduleresponse?view=dynamics-ce-odata-9
But I keep getting error message:
Object reference not set to an instance of an object.
Could anyone who has done web api calls to Dynamics 365 using OData or has any experience with this kindly help?

Quickly did a browser console test, the code snippet from this blog post works fine.
Pasting part of the snippet from the blog, your code may break as you are passing "Available" instead of ['0'] for TimeCodes.
var requestUrl = "/api/data/v9.0/QuerySchedule(ResourceId=#p1,Start=#p2,End=#p3,TimeCodes=#p4)";
requestUrl += "?#p1=" + context.getUserId().replace("{", "").replace("}", "");
//put Id of resource you want get data for as parameter 1
requestUrl += "&#p2=" + JSON.stringify(start).replace(/"/g, "");
requestUrl += "&#p3=" + JSON.stringify(end).replace(/"/g, "");
requestUrl += "&#p4=" + JSON.stringify(['0']);
Even you can paste this url in your browser address bar to smart test:
Request:
https://test.crm.dynamics.com/api/data/v9.0/QuerySchedule(ResourceId=#p1,Start=#p2,End=#p3,TimeCodes=#p4)?#p1=0EEE678F-C4FF-E711-A959-000D3A1A941E&#p2=2019-01-15T09:27:39Z&#p3=2019-01-15T21:27:39Z&#p4=['0']
You may notice ['0'] turn into [%270%27] but the below expected response will appear.
Response:
{"#odata.context":"https://test.crm.dynamics.com/api/data/v9.0/$metadata#Microsoft.Dynamics.CRM.QueryScheduleResponse","TimeInfos":[{"Start":"2019-01-15T00:00:00Z","End":"2019-01-16T00:00:00Z","TimeCode":"Available","SubCode":"Schedulable","SourceId":"15f40c32-1609-46db-93da-1bbb8eb19c9d","CalendarId":"69b0ee2b-bad7-4b8e-9bcc-d03e76b45a03","SourceTypeCode":4004,"IsActivity":false,"ActivityStatusCode":-1,"Effort":1.0,"DisplayText":""}]}

Related

How to read query parameter with ^ in the URL

I'm trying to implement a callback endpoint for eBay. This endpoint is called by eBay to hand the application a user token.
I can define my endpoint as expected
http://localhost:8080/api/ebay/auth
Nothing unusual here. My enpoint looks like this, really basic:
#RestController
#RequestMapping(path = ["/api/ebay/auth"])
class EbayAuthController {
#GetMapping(path = [""])
fun getAccessToken(#RequestParam code: String) {
println("Auth code: $code")
}
}
Now eBay passes the parameter code with the value
?code=v^1.1%23i^1%23r^1%23p^3%23I^3%23f^0%23t^[excluded_user_token]&expires_in=299
When I call my endpoint with this data set, it returns 400 Bad Request. I can reproduce this by adding ^ to any request. I read it's an unsafe character to use - but the issue is: Ebay uses this character to return the user token, so I must read it.
When I pass a sample with http://localhost:8080/api/ebay/auth?code=123 it prints the code as expected.
I've never encountered that problem, can anyone help me or point me in the right direction how to solve this?
According to this answer by Dirk Deyne to the question Spring-boot controller error when url contains braces character, you can specify server.tomcat.relaxed-query-chars in your application.properties:
server.tomcat.relaxed-query-chars=^

How do I pass connection-time websocket parameters to Phoenix from Elm?

I was following along Programming Phoenix but using Elm for my front end, rather than Javascript. The second part of that book describes how to use websockets. The book's running example has you create an authentication token for the client side to pass to Phoenix at connection creation time. The Javascript Socket class provided with Phoenix allows that, but there's no obvious way to do it in Elm (as of 0.17 and the date of this question).
As in the book, make the token visible to Javascript by attaching it to window.
<script>window.auth_token = "<%= assigns[:auth_token] %>"</script>
In web/static/js/app.js, you'll have code that starts Elm. Pass the token there.
const c4uDiv = document.querySelector('#c4u-target');
if (c4uDiv) {
Elm.C4u.embed(c4uDiv, {authToken: window.auth_token});
}
On the Elm side, you'll use programWithFlags instead of program.
Your init function will take a flags argument. (I'm using the Navigation library for a single-page app, which is why there's a PageChoice argument as well.)
type alias Flags =
{ authToken : String
}
init : Flags -> MyNav.PageChoice -> ( Model, Cmd Msg )
Within init, tack on the token as a URI query pair. Note that you have to uri-encode because the token contains odd characters. Here's the crude way to do that. Note: I am using the elm-phoenix-socket library below, but the same hackery would be required with others.
let
uri = "ws://localhost:4000/socket/websocket?auth_token=" ++
(Http.uriEncode flags.authToken)
in
uri
|> Phoenix.Socket.init
|> Phoenix.Socket.withDebug
|> Phoenix.Socket.on "ping" "c4u" ReceiveMessage
I got here by a Tweet by Brian, about encoding from Elm.
In this case I like to handle it from the JavaScript side.
I tried to replicate the way the Phoenix client sets it up.
Instead of passing the token I passed the complete endpoint...
I've put the token in JSON a hash
<script id="app-json" type="application/json"><%= raw #json %></script>
Which I read on the client, and pass to the Elm embed
var data = JSON.parse(document.getElementById("app-json").innerHTML)
var token = encodeURIComponent(data.token)
var elm = window.Elm.App.embed(document.getElementById("elm-container"), {
socketEndpoint: "ws://" + window.location.host + "/socket/websocket?token=" + token
})

Passing date parameters to #url.action via ajax

In my ASP.NET MVC 4 app, I'm using the following JAX code taken from this StackOverflow post to pass Date parameters to a controller but I am getting the following http 404 error: "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. Requested URL /myWebApp/myController/myAction/01/01/2014/12/31/2014"
Here the input controls txtFrom and txtTo have the values 01/01/2014 and 12/31/2014 respectively. the issue is that MVC is probably interpreting each date as three different parameters. How can we fix it. I tried replacing $('#txtFrom').val() with $('#txtFrom').val().replace("///g", "_") but it does not work.
window.location.href = '#Url.Action("myAction")/' + $('#txtFrom').val() + '/' + $('#txtTo').val();
Action method:
public ActionResult myAction(string startDate, string endDate)
{
//simple code here to use the input parameters
}
You could either format the date string with Razor
#HttpUtility.UrlEncode(date)
with javascript
encodeURIComponent(date)
or pass the date as ticks (milliseconds since Epoch) instead of the human-readable format.
Edit:
After experimenting with this and a bit of research it seems the slash and %2f encoding causes all kinds of problems. Stick to the millisecond representation for a date and not worry about passing the slash.
window.location.href is not ajax. Its your browser making a HTTP get request to the url. In your case, its not a complete url, but a partial; thus the error. You may try the following for start. Substitute the hardcoded values for dates with your inputs
$.getJSON({‘#Url.Action("myAction")’ + '/', { startDate: ‘1/1/2001’, endData: ‘1/2/2002’ }});
If you want to process any return value; refer to jquery documentation on $.getJSON (http://api.jquery.com/jquery.getjson/)

Need assistance with unfamiliar syntax, error - e is undefined - Google Apps Script(GAS)

I'm using a script exactly like the one on the tutorial here, https://developers.google.com/apps-script/reference/ui/file-upload
However, despite using the syntax I keep getting e is undefined in the statement:
var fileBlob = e.parameter.dsrFile;
I think that means my function doPost(e) is probably wrong somehow. Here is my entire script below.
// Create Menu to Locate .CSV
function doGet(e) {
var app = UiApp.createApplication().setTitle("Upload CSV");
var formContent = app.createVerticalPanel();
formContent.add(app.createFileUpload().setName("dsrFile"));
formContent.add(app.createSubmitButton("Start Upload"));
var form = app.createFormPanel();
form.add(formContent);
app.add(form);
return app;
}
// Upload .CSV file
function doPost(e)
{
// data returned is a blob for FileUpload widget
var fileBlob = e.parameter.dsrFile;
var doc = DocsList.createFile(fileBlob);
}
e is undefined because you are not passing anything to doPost. You have to pass the needed object to doPost. Check where you call the function and what parameters do you pass to it if any. Even if you pass a parameter to that function, it holds undefined value. Make sure that you are passing the correct objects to your functions.
Your script should work perfectly. e is defined by Google Apps Script, not need to pass anything in particular is contains the fields of your form, in particular in this case the file you uploaded.
I would suspect you may be falling foul to the dev url vs publish url syndrome, where you are executing an old scrip rather that the code you are currently working on.
Be sure you script end with 'dev' and not 'exec'
https://script.google.com/a/macros/appsscripttesting.com/s/AKfyck...EY7qzA7m6hFCnyKqg/dev
Let me know if you are still getting the error after running it from the /dev url

How do I call an SSJS method with parameters from javascript

I have a url containing a hash e.g http://www.acme.com/home.xsp#key=1234
When the url above loads in the browser I need to call a serverside javascript based on the value in the hash.
I have found a few ways of retriving the hash client side like this
var key = getHashUrlVars()["key"];
so I have the key available in my client side script in the onclientload event.
So in the same onClientLoad event I now need to call my server side javascript method so I have tried the following
'#{javascript:doStuff(key)}'
'#{javascript:doStuff(' + key + ')}'
..and a few other ways. but I can't get it to work.
maybe there is an XSP command I can use instead?
any ideas how to solve this?
You could do a XSP.partialRefreshPost in CSJS and use parameters to send your data to the server:
var p = { "key": getHashUrlVars()["key"] }
XSP.partialRefreshPost( '#{id:_element_to_refresh_}', {params: p} );
To access the parameters in SSJS just try this:
doStuff( param.key )
You could use an empty div-element as a target execute the SSJS code. Or you can use the executeOnServer - method: http://xpages.info/XPagesHome.nsf/Entry.xsp?documentId=88065536729EA065852578CB0066ADEC
Hope this helps
Sven

Resources