Geocoding using Google Geocoding Web Service - dynamics-crm-2011

I'm trying to geocode an address from Microsoft Dynamics CRM 2011 using Javascript.
I don't want to display the map, just perform the Geocoding and store the Lat / Long values in the database.
I keep getting an error message saying
"result.0 is null or not an object"
var url = 'http://maps.googleapis.com/maps/api/geocode/json?address=39 George Street, Belmont, WA, 6104, Australia&sensor=false'
var lat = url.results[0].geometry.location.lat();
alert(lat)
what am I doing wrong?

I assume from your question that this is a complete code snippet. On that assumption your code is incomplete. Your code creates a string called url. You then attempt to access a collection in that string, called results (which does not exist - and therefore position 0 within that colelction does not exist). Basically, your code doesn't do anything.
You need to have a good read of the Google Geocode API because, I'm sorry to say, you're not even close to getting this working... https://developers.google.com/maps/documentation/javascript/geocoding
Edit:
In the interests of being more helpful - here is a walkthrough too: http://www.wikihow.com/Geocode-an-Address-in-Google-Maps-Javascript

I have to disagree with Greg...you appear to have the request URL pretty close. Check out the Google Geocoding guide for the exacts. What you will get back is a JSON string, so you should use something like jQuery to parse the string into an object.
If you are not set on using JSON, then a simple script like this will also return the Lat/Lng (adapted from Google sample):
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var addressLocation = results[0].geometry.location;
alert("Lat: " + addressLocation.lat() + " Lon: " + addressLocation.lng());
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
</script>

Related

SMART on FHIR JavaScript API does not return JSON with out additional call to fetchAll for Observation in Cerner tutorial

I'm working on creating a SMART on FHIR application based on the Cerner tutorial at https://engineering.cerner.com/smart-on-fhir-tutorial/.
The following is called in example-smart-app.js
var patient = smart.patient;
var pt = patient.read();
var obv = smart.patient.api.fetchAll({
type: 'Observation',
query: {
code: {
$or: ['http://loinc.org|8302-2', 'http://loinc.org|8462-4',
'http://loinc.org|8480-6', 'http://loinc.org|2085-9',
'http://loinc.org|2089-1', 'http://loinc.org|55284-4']
}
}
});
I've modified slightly to the following:
<script>
fhirOnReady = function(smart) {
patient = smart.patient;
pt = patient.read();
var obv = smart.patient.api.fetchAll({
type: 'Observation',
query: {
code: {
$or: [
'http://loinc.org|8302-2',
'http://loinc.org|8462-4',
'http://loinc.org|8480-6',
'http://loinc.org|2085-9',
'http://loinc.org|2089-1',
'http://loinc.org|55284-4'
]
}
}
});
var populatePatientData = function(patient) {
$("#fname").html(patient.name[0].given);
$("#lname").html(patient.name[0].family);
$("#gender").html(patient.gender);
$("#dob").html(patient.birthDate);
}
$.when(pt, obv).fail(fhirOnError);
$.when(pt, obv).done(
function(patient, obv) {
populatePatientData(patient);
$("#patientJson").html(JSON.stringify(patient,undefined,2));
$("#patientSuccessMsg").html("<h1>Congratulations, you've also successfully loaded a patient using SMART on FHIR</h1>");
}
);
};
fhirOnError = function() {
$("#patientJson").html("An error occurred.\nThis is expected if you are looking at this page from a browser.");
};
FHIR.oauth2.ready(fhirOnReady, fhirOnError);
</script>
If I run the above using the SMART App Launcher at https://launch.smarthealthit.org/ everything seems to work as expected.
However, if I remove the call to smart.patient.api.fetchAll for the observations the patient JSON string is empty.
What is the correct way to get the entire patient resource using the SMART on FHIR JavaScript Library described at http://docs.smarthealthit.org/client-js/?
---EDIT ----------------------------------
If I try to implement using the code in the documentation at http://docs.smarthealthit.org/client-js/#smart-api I get the error shown below.
Code
<!-- index.html -->
<script src="./node_module/fhirclient/build/fhir-client.js"></script>
<script>
FHIR.oauth2.ready()
.then(client => client.request("Patient"))
.then(console.log)
.catch(console.error);
</script>
Error
Libraries are taken directly from the Cerner tutorial.
SMART apps usually have a "patient" in context that is already part of the data passed over to the system from which you are trying to elicit information. In this case you are trying to hit the Cerner FHIR server to get the observations linked to that Patient. Two things are possible at this point:
The Server may not have the Patient resource, which is why it is using the Id of the patient to fetch all observations
Check your smart SCOPEs, you may not be allowed to read Patient records in it's entirety.
Usually the FHIR endpoint can be deciphered using Fiddler following the launch sequence. As per the SMART exchange the CapabilityStatement is queried for the authorization and Token endpoints. If you are able to see the server then you can tack on the /Patient/id to get the resource but this means you have to have a valid token and the appropriate scope statements in place.

SuiteScript 2 Email Invoices

Hi and I I am not a pain, I got help on sending a statement and that worked perfectly, but I need to send invoices with it but I can't find a method for that like I did for the statement. I find references to using a template file, then you have to store the file in the cabinet. I have to attach there to emails, what would you think the best way to do this?
Here is the other link, he gave a very helpful complete answer about sending statements. I should have asked him about invoices at the same time but I didn't think of it, apologies.
SuiteScript 2 can send pdf statements
added additional info
Ok I tried this but I am getting an error that doesn't make sense as I am using their templates.
"error.SuiteScriptError","name":"USER_ERROR","message":"Error Parsing XML: The reference to entity \"c\" must end with the ';' delimiter.",
require(['N/render', 'N/file', 'N/record'],
function(render, file, record) {
function renderRecordToPdfWithTemplate() {
var renderer = render.create();
renderer.setTemplateByScriptId("STDTMPLCUSTINVC");
var xml = renderer.renderAsString();
renderer.addRecord(record.Type.INVOICE, record.create({
type: record.Type.INVOICE,
id:415619
}));
var invoicePdf = renderer.renderAsPdf();
var foo = this;
}
renderRecordToPdfWithTemplate();
});
thanks for any help with this
Ok I found it thanks if anyone was looking for this for me. It is pretty straightforward, but like NetSuite always is, you have to find it. :)
the entityid is the invoice internalid the rest is easy, then just pass the file object to the email.
require( [ 'N/render', 'N/file', 'N/record' ],
function( render, file, record ) {
function renderRecordToPdfWithTemplate() {
var transactionFile = render.transaction({
entityId: 415619,
printMode: render.PrintMode.PDF
});
var foo = this;
}
renderRecordToPdfWithTemplate();
} );
thanks again

Paging in MS Graph API

Graph API Paging explains that the response would contain a field #odata.nextLink which would contain a skiptoken pointing to the next page of contents.
When I test the API, I'm getting a fully-qualified MS Graph URL which contains the skiptoken as a query param. E.g. Below is the value I got for the field #odata.nextLink in the response JSON.
https://graph.microsoft.com/v1.0/users?$top=25&$skiptoken=X%27445370740200001E3A757365723134406F33363561702E6F6E6D6963726F736F66742E636F6D29557365725F31363064343831382D343162382D343961372D383063642D653136636561303437343437001E3A7573657235407368616C696E692D746573742E31626F74322E696E666F29557365725F62666639356437612D333764632D343266652D386335632D373639616534303233396166B900000000000000000000%27
Is it safe to assume we'll always get the full URL and not just the skiptoken? Because if it's true, it helps avoid parsing the skiptoken and then concatenating it to the existing URL to form the full URL ourselves.
EDIT - Compared to MS Graph API, response obtained from Azure AD Graph API differs in that the JSON field #odata.nextLink contains only the skipToken and not the fully-qualified URL.
if you would like to have all users in single list, you can achieve that using the code that follows:
public static async Task<IEnumerable<User>> GetUsersAsync()
{
var graphClient = GetAuthenticatedClient();
List<User> allUsers = new List<User>();
var users = await graphClient.Users.Request().Top(998)
.Select("displayName,mail,givenName,surname,id")
.GetAsync();
while (users.Count > 0)
{
allUsers.AddRange(users);
if (users.NextPageRequest != null)
{
users = await users.NextPageRequest
.GetAsync();
}
else
{
break;
}
}
return allUsers;
}
I am using graph client library
Yes. In Microsoft Graph you can assume that you'll always get the fully qualified URL for the #odata.nextLink. You can simply use the next link to get the next page of results, and clients should treat the nextLink as opaque (which is described in both OData v4 and in the Microsoft REST API guidelines here: https://github.com/Microsoft/api-guidelines/blob/master/Guidelines.md#98-pagination.
This is different from AAD Graph API (which is not OData v4), which doesn't return the fully qualified next link, and means you need to do some more complicated manipulations to get the next page of results.
Hence Microsoft Graph should make this simpler for you.
Hope this helps,
The above code did not work for me without adding a call to 'CurrentPage' on the last line.
Sample taken from here.
var driveItems = new List<DriveItem>();
var driveItemsPage = await graphClient.Me.Drive.Root.Children.Request().GetAsync();
driveItems.AddRange(driveItemsPage.CurrentPage);
while (driveItemsPage.NextPageRequest != null)
{
driveItemsPage = await driveItemsPage.NextPageRequest.GetAsync();
driveItems.AddRange(driveItemsPage.CurrentPage);
}
I followed Tracy's answer and I was able to fetch all the messages at one go.
public List<Message> GetMessages()
{
var messages = new List<Message>();
var pages = Client.Users[_email]
.Messages
.Request(QueryOptions)
// Fetch the emails with attachments directly instead of downloading them later.
.Expand("attachments")
.GetAsync()
.Result;
messages.AddRange(pages.CurrentPage);
while (pages.NextPageRequest != null)
{
pages = pages.NextPageRequest.GetAsync().Result;
messages.AddRange(pages.CurrentPage);
}
return messages;
}

Accessing current user information for a netsuite html form using suitescript

I've been trying to figure auto-complete some values from netsuite onto our custom html form.
After a bit of researching, I found this gem: nlapiGetContext (http://www.netsuite.com/portal/developers/resources/APIs/Dynamic%20HTML/SuiteScriptAPI/MS_SuiteScriptAPI_WebWorks.1.1.html)
which should do exactly what it says,
However, when doing a console.log dump of nlapigetcontext()
the following information is displayed, not my current logged in user information
Here is my current test script:
if (window.addEventListener) { // Mozilla, Netscape, Firefox
window.addEventListener('load', WindowLoad, false);
} else if (window.attachEvent) { // IE
window.attachEvent('onload', WindowLoad);
}
function WindowLoad(event) {
alert(nlapiGetContext().getCompany());
console.log(nlapiGetContext());
}
Any help or guidance is appreciated!
Thank you!
Where is this form located? Context will only work if you are logged into the system, so this won't apply for online customer forms, those are considered to be "outside the system".
You can write a Suitelet to retrieve data from an external form if you are only retrieving values.
I use this to get campaign information on an external landing page.
function getCamData(request, response){
if ( request.getMethod() == 'GET' ){
response.setHeader('Custom-Header-CamID', 'CamID');
var camid = request.getParameter('camid');
var rec = nlapiLoadRecord('campaign', camid);
var o = new Object();
o.thisid = camid;
o.promocode = rec.getFieldValue('campaignid');
o.phone = rec.getFieldValue('custevent_cam_1300num');
o.family = rec.getFieldValue('family');
var myString = JSON.stringify(o);
response.write (myString);
}}
You request something like this:
https://forms.netsuite.com/app/site/hosting/scriptlet.nl?script=188&deploy=1&compid=xxxxxx&h=fb8224b74b24907a79e6&camid=8020
And returns something like this:
{"thisid":"8020","promocode":"CAM999","phone":"1800 111 222","family":"12"}
Also you can do server-side posting from an external site to a NetSuite customer online form, it will capture and validate the data as far as it has the entry fields set in NS, this is a great way to avoid using those horrible iframes.
Use these functions
nlapiGetContext().getName()
nlapiGetContext().getUser()
nlapiGetContext().getRole()
nlapiGetContext().getRoleId()
nlapiGetContext().getRoleCenter()
nlapiGetContext().getEmail()
nlapiGetContext().getContact()
nlapiGetContext().getCompany()
nlapiGetContext().getContact()
nlapiGetUser()
nlapiGetDepartment()
For details check http://suitecoder.appspot.com/static/api.html

Redirect, and keep query string [javascript]

I want to create a re-direct in JavaScript for the following functionality;
Once someone has landed on a webpage, there will be a JavaScript that will temporarily direct them onto a webpage (they will be on this webpage for a very short time, so the page can capture the cookie/IDs), and then redirected again to a different webpage;
So for example:
I land on www.bbc.co.uk?ID=1234, I then get directed to another webpage, which is carrying my query string, www.google.com?ID=1234, then immediately I get directed to the final webpage, www.facebook.com.
And there maybe 1, or more query strings that will need to be carried over from bbc onto google. No query strings on the third and final webpage.
I want to ask, if this is possible? It must be in JavaScript, I know to direct somebody in JS it's simply;
So far, my workings as:
window.location.href =
I can get the query strings by:
var vars = [], hash;
var q = document.URL.split('?')[1];
if(q != undefined){
q = q.split('&');
for(var i = 0; i < q.length; i++){
hash = q[i].split('=');
vars.push(hash[1]);
vars[hash[0]] = hash[1];
} }
Help/Advise will be very appreciated!
You can get the query string of the window with the following call: window.location.search
http://www.w3schools.com/jsref/obj_location.asp

Resources