Advertisements

Archive

Posts Tagged ‘ADX’

‘Address Suggestions’ in Portals using Esri ArcGIS

September 15, 2019 Leave a comment

In our Dynamics Portals, we got a requirement to show ‘Address Suggestions’ as and when the end user start typing the address.

We implemented the solution by consuming the Esri ArcGIS mapping service, from our Portal’s web page.

ESRI_1

‘Entity Form’ with Address Suggestions

In this article lets see how to implement this at a high level.

What is ESRI ArcGIS?

  • Its a cloud based mapping and analytics platform.

ESRI_3

  • For our ‘Address Suggestions’ requirement, we have consumed ESRI ArcGIS’s World Geocoding Service
  • World Geocoding Service:
    • Its part of ESRI ArcGIS.
    • This Service finds addresses and places in all supported countries from a single endpoint.
    • The service can find point locations of addresses, business names, and so on.

Steps to fetch ‘Address Suggestions’:

  • To fetch the ‘Address Suggestions’, we have used findAddressCandidates operation of ‘World Geocoding Service’.
  • findAddressCandidates operation is REST based and takes ‘Input address’ as parameter.
  • As an example, to fetch the ‘Microsoft Office’ addresses in ‘Redmond’ the REST URL would be as follows:

https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?SingleLine=Microsoft+Redmond&sourceCountry=USA&category=&outFields=*&forStorage=false&f=pjson

ESRI_2

  • In the above URL,
    • ‘findAddressCandidates’ –  Operation name.
    • ‘SingleLine’ – Parameter which you need to pass address you are looking for (i.e., Microsoft+Redmond). Use + symbol to combine the words.
    • ‘sourceCountry’ – Optional parameter. if provide, results will be specific to provided country code.
  • Below is the sample script to call the service from Portal Web Page/Entity Form/ Web Templates.

function GetAddressrecommendations(address) {
var url = https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?SingleLine=”+address+”&category=&outFields=*&forStorage=false&f=pjson;
// To limit the address to ‘United States’ country uncomment below line
// url += “&sourceCountry=USA”;

var xhr = createCORSRequest(“GET”, url);
if (!xhr) {
throw new Error(“CORS not supported”);
}
xhr.onload = function () {
var text = xhr.responseText;
// Success and add logic to Parse the Response.
};
xhr.onerror = function () {
alert(“Unable to fetch addresses.”);
};
xhr.send();
}

function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if (“withCredentials” in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != “undefined”) {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}

How to call the method?

  • Call the GetAddressrecommendations function by passing the address you are looking for
    • GetAddressrecommendations(‘Microsoft+Redmond’)

Notes:

  • Esri ArcGis platform provides both hosted GIS services and a portal with a web UI and APIs for publishing, sharing, and managing content, maps, applications, and users.
  • It has both Free and Paid services. Read the documentation before making the decision.

🙂

Advertisements

Dynamics/ADX Portals – Create Notes using SDK

As part of an integration requirement, we had to create ‘Notes’ (i.e., Annotation) with attachment using SDK.

Key Notes:

  • ‘Subject’ and ‘Notetext’ field values of Portal Notes follows a specific pattern than that of Dynamics.  Values must be set as follows:
    • SubjectNote created on {DateTime.Now.ToString()} by {Portal User Name} [contact:{PortalUserGUID}]
      • If the Portal user name is ‘Rajeev P’ and Portal user GUID(i.e.,Contact record’s GUID) is ‘2510ae27-7289-e911-a958-001dd800d97c’, Subject will be Note created on {DateTime.Now.ToString()} by Rajeev P [contact:2510ae27-7289-e911-a958-001dd800d97c]
    • Notetext*WEB*
  • If you don’t pass Portal User’s GUID in ‘Subject’ field, Portal shows the Notes record created by as User whom the Portal was configured.

Code to create Annotation:

Below is the code snippet

var noteSubject = “Note created on {DateTime.Now.ToString()} by Rajeev P [contact:2510ae27-7289-e911-a958-001dd800d97c]“;

var entAnnotation = new Entity(“annotation”);
entAnnotation[“subject“] = noteSubject;
entAnnotation[“notetext“] = “*WEB*”;
entAnnotation[“filename”] = {File_name}; // Set FileName
entAnnotation[“documentbody”] = {Base64String}; // Pass document body in Base64 format
entAnnotation[“isdocument”] = true;
entAnnotation.Attributes[“objectid”] = new EntityReference({RegardingSchemaName}, {RegardingGuid}); // Set Schema and GUID
entAnnotation.Attributes[“objecttypecode”] = {RegardingSchemaName}; // Set Schema

var noteId = crmService.Create(entAnnotation);

  • Note : Replace values in {} with actual values.

🙂

 

 

ADX Portals – Clear Cache On Web Page Submission

Adxstudio Portal application caches the results from Dynamics CRM to improve the performance.

But, there are times, where we need to override (invalidate) cache behavior to show latest data on Portals. Lets take a scenario

  • My Portal has a ‘Contact’ web page and up on ‘Submit’, a plug-in updates all the associated ‘Cases’ in the background.
  • Now, on Portal, navigate to ‘Cases’ entity list Web Page, which should show the latest ‘Cases’ data, which has been updated by plug-in in above step.

In above scenario, we will not get the latest ‘Cases’ due to Portal Cache behavior.

So what are the ‘Cache Invalidation’ options?

  • Manual Cache Invalidation:
    • This option is to manually hit the JavaScript bookmark-let  as specified here.
    • Drawback:
      • Its not viable, to ask portal users to hit the URL every time they ‘Submit’ the ‘Contact’ web page
  • Web Notifications:
    • A Web Notification Plugin registered with the Adxstudio Portals solution in CRM is triggered on all entity create, update, delete, disassociate, associate, publish, and publish all messages and notifies the Web Notification URLs defined in the CRM to invalidate the cache so the users visiting the portal get the recent data changes
    • Drawback:
      • A ‘System Job’ gets created up on update of the entity, and the execution may get delayed based on the occupancy of CRM Async Service Job.
      • This is not fool proof solution.

ADX Cache_1

We took an approach to automate the ‘Manual Cache Invalidation’ process to fetch the latest CRM data.

Our Cache Invalidation Approach :

  • Create a new ‘Web Page’ and paste below ‘Manual Cache Invalidation JavaScript’ code in ‘Custom JavaScript’ field.
    • Note: You don’t need to associate any ‘Web Form’, ‘Entity List’ or ‘Entity Form’ to this Web Page.

$(document).ready(function () {
var url = document.location.protocol + ‘//’ + document.location.host + (document.location.host.indexOf(“demo.adxstudio.com”) != -1 ? document.location.pathname.split(“/”).slice(0, 3).join(“/”) : “”) + ‘/Cache.axd?Message=InvalidateAll&d=’ + (new Date()).valueOf();
var req = new XMLHttpRequest();
req.open(‘GET’, url, false);
req.send(null);
// Redirect to Portal Home Page
window.location.href = ‘../’;
});

  • In below screen, I created a new Web Page ‘Portal Cache Clear’ and copied the above script.

ADX Cache_2

  • So, to invalidate ‘Cache’ on the ‘Submit’ of any of your Portal form, In Entity Form’s ‘On Success Settings’, Redirect to Cache ‘Web Page’ as configured in below screen.

ADX Cache_3

  • That’s it. Your portal should invalidate cache, up on Entity Form submission. One caveat of this approach is, ‘Portal Cache’ web page will flash for few seconds before redirecting to portal’s ‘Home’ page.

Note:

  • This Information is Relevant to Legacy Adxstudio Portals Only.
  • Dynamics 365 Portal Add-on’s Do Not Require this Configuration.

🙂

 

 

Categories: ADX Tags: ,

[Code Snippet] Dynamics Portals/ADX – Set ‘Field Requirement’ using script

April 28, 2019 1 comment

Below is the code snippet to set the requirement level (i.e., Required/Non-Required) of a field using script in portals. This logic handles all kind of field types including Check boxes.

Set Field As Required:

function SetFieldAsRequired(fieldName) {
if (typeof (Page_Validators) == ‘undefined’) return;
if ($(“#” + fieldName) != undefined && $(“#” + fieldName + “_label”) != undefined) {
$(“#” + fieldName).prop(‘required’, true);
$(“#” + fieldName).closest(“.control”).prev().addClass(“required”);

// Create new validator object
var Requiredvalidator = document.createElement(‘span’);
Requiredvalidator.style.display = “none”;
Requiredvalidator.id = fieldName + “Validator”;
Requiredvalidator.controltovalidate = fieldName;
Requiredvalidator.errormessage = “<a href=’#” + fieldName + “_label’>” + $(“#” + fieldName + “_label”).html() + ” is a required field.</a>”;
Requiredvalidator.initialvalue = “”;
Requiredvalidator.evaluationfunction = function () {
var fieldControl = $(“#” + fieldName);
if (fieldControl.is(“span”)) {
var value0 = $(“#” + fieldName + “_0”).prop(“checked”);
var value1 = $(“#” + fieldName + “_1”).prop(“checked”);
if (value0 == false && value1 == false) {
return false;
} else {
return true;
}
}
else {
var value = $(“#” + fieldName).val();
if (value == null || value == “”) {
return false;
} else {
return true;
}
}
};

// Add the new validator to the page validators array
Page_Validators.push(Requiredvalidator);
}
}

Set Field As Non Required:

function SetFieldAsNonRequired(fieldName) {
if (typeof (Page_Validators) == ‘undefined’) return;
if ($(“#” + fieldName) != undefined) {
$(“#” + fieldName).closest(“.control”).prev().removeClass(“required”);
$(“#” + fieldName).prop(‘required’, false);

for (i = 0; i < Page_Validators.length; i++) {
if (Page_Validators[i].id == fieldName + “Validator”) {
// Remove the current field’s ‘Required’ validator from ‘Page_Validators’ array
Page_Validators.splice(i);
}
}
}
}

How to use the functions:

  • Above functions can be called from ‘Custom JavaScript’ tab of Portal’s ‘Entity Form’.
  • Pass the Dynamics field’s schema name as the parameter to both functions.
    • In below example, ’emailaddress1′ is the field name which I want to set the Requirement level.

ADXJ_1

Refer the article for Portal script syntax’s and usage.

🙂

 

ADX Portals 7.x – ‘Page_Validators’ is undefined

Other day, while adding a custom validator using JScript on an Entity Form, I was getting ‘Page_Validators’ is undefined error, at below line of code.

// Add the custom validator to Web Page’s validators array
Page_Validators.push(spouseValidator);

Reason:

  • The dynamics CRM form, associated to the ADX Entity Form, does’t have any required field, hence ‘Page_Validators’ array is NULL as ADX did’t need to load any validators.

Fix:

  • ‘Page_Validators’ is a validator collection and we dont have control over this.
  • Below workaround worked for us:
    • Make one of the field as ‘Required’ by adding ‘Entity Form Metadata’. ADX instantiates ‘Page_Validators’ array, as there is Required field now.
    • You can make the field as Non-required in the JScript.

Metadata_1

Note:

  • This behavior is fixed in further versions of ADX and Dynamics Portals.

🙂

 

 

ADX/Dynamics Portals Issue – Missing Entity ‘Tab’ in ‘Web Form Step’

We have ADX portal 7.0 solution installed on our Dynamics 365 8.2 application. We got a requirement to create a Web Form steps on a Custom Entity ‘Employee’.

‘Employee’ entity has an OOB ‘Information’ of ‘Form Type’ Main, with a tab named ‘Personal Details’.

PWF_1

Issue:

  • While adding a Web Form step, there was no ‘Personal Details’ tab and could get only ‘general’ tab.
  • In the new ‘WEB FORM STEP’, select the ‘Form Name’

PWF_2

  • In the ‘Tab Name’ drop down, there is no ‘Personal Details’ tab and all it had was ‘general’ tab.

PWF_3

Reason:

  • As there were 2 OOB forms (i.e., Form Type ‘Main’, ‘Mobile – Express’) with the same name ‘Information’, ADX solution always picking ‘Mobile – Express‘ form which had a tab ‘general’

Fix:

  • Renamed ‘Information’ Main form to ‘Employee’.

PWF_4

  • Publish the solution
  • Refresh the ‘Web Form Step’ and you should see ‘Personal Details’ tab once you select the ‘Employee’ form.

PWF_5

🙂

Categories: ADX, Dynamics 365 Tags: , ,