Rewriting Xrm.Page

By Robin Pietens (Dynamics 365 Consultant @ Capgemini)
 
For those that have not yet heard: Microsoft has decided to deprecate the use of Xrm.Page.

Microsoft did indicate their understanding that this feature is used a lot, so they will retain compatibility with it for quite some time. However, new functions should be written in a way that is as future-proof as possible right? For some reason I was unable to easilly find a nice overview of what we should change to deal with this deprecation, and I decided to do something about that.
 

So where we used to write:

function doSomething(){
     var some = Xrm.Page.getAttribute("new_some").getValue(); 
     var action = Xrm.Page.getAttribute("new_action").getValue(); 
     console.log(some + " " + action); 
}

 

We should now do something else, and write:

function doSomething(executionContext){
     var formContext = executionContext.getFormContext(); // get formContext 
     // use formContext instead of Xrm.Page 
     var some = formContext.getAttribute("new_some").getValue(); 
     var action = formContext.getAttribute("new_action").getValue(); 
     console.log(some + " " + action); 
}

 

The other thing to do is to check the box of ‘pass execution context as first parameter’ when setting up the function on the form. If you, like me, make parameters of just about anything, simply pass them with comma’s separated from the executioncontext. Then put everything except the executioncontext in the box as comma separated parameters that will be passed to the function:
 


 

And the function itself will look like this:

function doSomething(executionContext, firstparam, secondparam){
     var formContext = executionContext.getFormContext(); // get formContext
     var some = formContext.getAttribute(firstparam).getValue(); 
     var action = formContext.getAttribute(secondparam).getValue(); 
     console.log(some + " " + action); 
}

 

Any new Scripts that you write should conform to the standard outlined in this blogpost. When making changes to existing libraries, it’s a good idea to take it into account as well. Talk the costs and benefits through with your customer, to keep them as upgrade-proof as possible!

If you want to stay up-to-date with features like this one, keep an eye out for new blogposts and follow us on LinkedIn.

For (hard to find) Microsoft references see: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/clientapi-form-context

Tips to improve User Adoption

By Robin Schaareman (Dynamics 365 Consultant @ Capgemini)

We have all probably seen a situation like this before, a customer has a Dynamics CRM/365 solution which is in use for several years but the adoption of the system is not satisfying enough. The client asks you to help improve their user adoption of Dynamics CRM/365. Improve user adoption is not an easy task. Via this article I want to give some tips/guidelines that can be used to help a customer improve their user adoption. Let’s start at the beginning….

1.Back to the beginning

To make sure you can start off with a solid solution for your client you need to take them back to the beginning. Why was CRM introduced in the first place? Did CRM solve the problem the client had? These are typical questions you can ask your customer in order to get a good picture of the situation.

 

2.Demonstrate the benefits

There will always be users that did not have a problem with the previous way of working and don’t see the value of the CRM system. Therefor it is extremely important to show the benefits of the CRM system. Even when the system has been live for some time it can be good to demonstrate new features or updates.

 

3.Involve users

Always involve the “daily” users when it comes to maintenance or development of the CRM system. Give them a voice when it comes to new features or changes in the system.  This can be done via several ways. The most important one is communicating about the CRM system. New features, roadmap, tips and tricks etc. Try to find topics which suit the users most so they are actually interested in the message you are spreading. This is one way of communicating, you can also try to organize workshops/training sessions every now and then to demo new features. These sessions are also a great way to interact with the end user!

 

4.Recruit champions!

Reach out to enthusiastic and influential business users to help improve user adoption. This will help with the overall usage of CRM. These so-called champions (this is just an example, you can name this group of people to your liking 😊) are the first point of contact for the other users. They are willing to help other users understand the system and are very valuable for you when it comes to information. Not every user complains via the helpdesk or via a ticketing system about the struggles they have with the system. Champions who are working with these users will pick up some of these complaints, and can inform you, the developper, and even help you think of a solution!

 

5. Keep it simple

CRM is very complex and can be confusing at some points. Keep the interface (e.g. forms ) clean with attributes that users currently need. A cluttered interface won’t help in making the system easy to work with. This can be done via some best practises for example; WYSIATI (What You See Is All There Is) and to let the user flow through the form with the help of a business process flow.

 

6. Sharing is caring

It can be hard in some environments to make this happen but keep in mind that CRM works best if you share the information in it. Dashboards, reports and views will be more valuable if there is a lot of data that can be used. Try to demo this to the business more often to show the benefits, this will help in security discussions you might have with compliance.

 

7. Accessibility

Make the CRM system accessible in various ways so the user can interact with CRM which suits them best. Tablet or Phone, but also on the browser and via the Outlook app! All these ways contribute in user adoption since these options will help the user create records easily.

 

8. Keep up the pace

And at last, keep up the pace! If your time to market is short, users will come to an understanding, that giving feedback about the system actually changes it as well. This will motivate users to actively think about their CRM system.

Dynamics 365 Portals – Set & use cookies

By Ritchey Hazeu (Dynamics 365 Consultant @ Capgemini)

 

Do you want to let users fill in data in the Portal and use this data later in other fields of a WebForm or EntityForm? We can use Cookies to help us achieving this.

In this example we give the customer the opportunity to send in multiple cases. After completing the first case we don’t want them to fill in every field again. We can use Cookies to store information from the first case and use that in the next cases. Let’s start!

 

1. Create a Webform with Contact information page.

 

2. In CRM, navigate to the Contact Information page by going to Portals -> Webforms -> Webform Steps.

 

 

3. Scroll down to the ‘Custom Javascript’ section.

 

Here we fill in the code to store the Cookie for this particular page. In this example we will only store 3 items.

This is the code I’m using:

$(document).ready(function () {
$( "#NextButton" ).click(function() {
console.log("clicked next -> Cookie stored");
document.cookie = "firstname=" + document.getElementById("new_voornaam").value;
document.cookie = "lastName=" + document.getElementById("new_achternaam").value;
document.cookie = "street=" + document.getElementById("new_straat").value;
});
});

 

4. After you submitted the code, you can check if the cookies are being stored.

In Chrome you can use the console by clicking on F12, go to application and then to cookies. It should look like this:

 

 

5. Now the cookies are being stored, we want to use them on other places.

Remember that, in this example, we want to give the customer the possibility to enter multiple cases. On the last page of the Webform we can redirect them to a new case. It’s important to refer to the existing WebPage.

 

 

And besides this you have to fill in the Redirect Webform step at ‘Next step’ at the last page.

 

 

6. We have set the cookies, now we are going to get the cookies.

We can add the new code to the existing code, because we are using it on the same form. If you want to use the data on other forms you have to place the getCookie function on a different page than the setCookie function. The new code will look like this:


function getCookie(name)
{
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
}


var firstname = getCookie("firstname");
var lastName = getCookie("lastName");
var street = getCookie("street");

$(document).ready(function () {
$("#new_voornaam").val(firstname);
$("#new_achternaam").val(lastName);
$("#new_straat").val(street);
});

$(document).ready(function () {
$( "#NextButton" ).click(function() {
console.log("clicked next -> Cookie stored");

document.cookie = "firstname=" + document.getElementById("new_voornaam").value;
document.cookie = "lastName=" + document.getElementById("new_achternaam").value;
document.cookie = "street=" + document.getElementById("new_straat").value;
});
});

 

7. If we are creating a new case, the fields are automatically populated:

 

 

If you have extra questions regarding Cookies in Dynamics 365 Portals or other question about Portals & Dynamics 365, please leave a comment.

 

And that’s how the cookie crumbles !