Thursday, 31 May 2018

Dynamics CRM: HTML Games


In Microsoft Dynamics 365 we can create multiple Add-ons with help of capability of HTML, Javascript and CSS.

Now these HTML 5 is becoming more popular and powerful and most of the browser start supporting HTML 5. HTML 5 give us some more interesting elements. Today I will discuss about “Canvas” element of HTML5.

HTML Canvas: -
                                Canvas is an element of HTML5 which in use to draw graphics in our html web resource.

We can also create runtime “Canvas” element in our HTML with help of Javascript.   We can think canvas as MS Paint board and with help of Javascript we can draw line, circle, square text, images. We can are also add motion in our elements of canvas.

We will look two examples to understand use of canvas.
  • Clock
  • Moving Square Game.

In the end I will also share solution that you can import in your CRM online trails and Play the game.













Clock: -
                To create Clock, we will use arc method to draw clock outline as circle. We will use fillText method to draw numbers. And lineTo method to design hour, minute and second hands.
We will also use setInterval Javascript function, so our clock should show as real clock.
Moving Square Game: -

                                                In this example we will create a Game for Dynamics CRM. This game needs a moving Square box, some Obstacles, a score counter and event handler for buttons and handlers for keystrokes.
We need to move our square box so it should not touch obstacles. If obstacles touch the screen than game over and need to restart the game.


We can store our scores in CRM and can give some points to winners.

Special thanks to W3school.com to help learning.

Now start your imagination and build some look add-ons for Dynamics CRM.


Please follow to be update for my blogs.



Tuesday, 15 May 2018

Dyanmics CRM : Change Version


Microsoft provide us liberty to create Trial version of Dynamics CRM. When we create a new trial, version of Dynamics CRM it always creates latest available version of Dynamics CRM.


But there are few scenarios where we need lower versions of Dynamics CRM.
  • Our client working on previous versions.
  • We have any solution which created in lower version.
  • We need to compare our solution in different versions.
  • We need previous versions for study.

Now I will demonstrate who you can downgrade your Online trial version.
Note: - Microsoft allows to downgrade version up to three previous versions.

Currently, when we create a new trail version it will create in Dynamics 365, version 9.0.
It will look like.











Declaration: - When you downgrade your CRM you will lose you all data and customization. So, play with care.
Now, we want to downgrade our latest trial version so follow these steps.
Make sure you are global admin. Go to admin panel 






































Expand “Admin centers” tab and click on “Dynamics 365”





































It will open Instance Picker page. So now select your organization and click on “Edit” button.

























Change Instance Type to “Sandbox”. This is required because we are not allowed to change version of production instance.






































After changing instance type, when we select our sandbox instance we will see more option in right had side.























Now click on “RESET” button.

 Now we can select our desired target version. We can select in between version 9.0, version 8.2 or Microsoft Dynamics CRM Online 2016 Update 1. We can also use other option like name change etc. as per our requirement.
























And click on reset button.
 It will take some time. It can take 15 minutes to 1 hour to configure your changes.




















After these changes are done you can change “Instance Type” again back to production.
Login to your CRM organization. Now you will see your Trial version changed and have no solution there.

Please follow to be update for my blog.

Wednesday, 9 May 2018

Dynamics CRM : Composite Fields


Dynamics CRM provide Composite Address for Lead, Account and Contact entity. Currently there is no option to create custom composite attribute Might be in future Microsoft provide this capability.
In this article we will understand below topics: -

  • Composite Field
  • Lookup attribute filter
  • Passing message(Event) from CRM form to HTML web resource
  • Sending Parent Control in open form
  • Download Solution


1. Composite Field: - 
                                     As name says composite field is made of two or more fields. Before Dynamics CRM 2016 Address was only composite field preset in CRM, but now we have two composite attributes.
First Address attribute and second is Customer attribute.

At database level separate table is created to handle composite attributes.
Example: - When we create a new account in CRM from web, console, integration etc. (Except SQL insert query-not recommended, but possible) with or without address. Two records are created in address table for that account. This address table contains Guid and Record type for reference of created record.
Customer Attribute is special type of attribute which contain reference of account and contact entity. For Customer attribute also have different table created at database level.

Difference between Address and Customer composite attribute is we can create custom Customer attribute for our entity, but we cannot create custom composite Address.

2. Lookup attribute filter: - 
                                               From Dynamics CRM 2016 onward, we can configure filter for our lookup without use of any Javascript code. To enable lookup filter target entity must contains in source entity and target entity must contain in current entity.
Working: -
Current Entity: Composite Field
Source Lookup: State lookup
Target Lookup: Country lookup










































Open form editor and select state attribute and click on change properties. In Display tab we will see new “Related Record Filtering” option.
Now select country attribute and contains state.



For this filter State entity must contains Country lookup.


After this configuration when we select country, state will only show for selected country.


3. Passing message(Event) from CRM form to HTML web resource: - 
                                                                                                                    As we know we can use Dynamics CRM XRM library in our HTML web-resource with use of window.parent
window.parent.Xrm
But passing information from CRM form to HTML web-resource is little compilated.
It involves two step processes
First, create a function in Javascript an register onload, OnChange, OnSave or any other form event to post message to html web resource.
Second, create an event listener in your HTML web resource to process message.

Example: -
Create JavaScript web resource and add function to Post message to HTML web resource.

function CompositeFieldFunction()
{
   
    if (Xrm.Page.ui.controls.get('WebResource_CompositeHtml')) {
        var iFrame = Xrm.Page.ui.controls.get('WebResource_CompositeHtml').getObject();
        var sav_address = window.parent.Xrm.Page.getAttribute("sav_address").getValue();
        if (sav_address) {
            iFrame.contentWindow.postMessage({ 'addressDiv': sav_address[0].name }, '*');
        }
        else
            iFrame.contentWindow.postMessage({ 'addressDiv': "Click here to add address" }, '*');
    }
}

Friday, 4 May 2018

Dynamics 365: TLS connection Issue

In Dynamics 365 after release of version 9.0 we started facing issue while connecting to Dynamics CRM in our console , window etc. application.

You will face below issue.

{"The underlying connection was closed: An unexpected error occurred on a send."}











Solution: -

Reason behind this issue Dynamics 365 version 9.0 following TLS 1.2.
That means you are not able to connect Dynamics 365 until you enforce TLS 1.2 before your connection.

So you need to use below code before creating connection.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;















After adding this code you will able to create connection successfully.

Due to TLS 1.2 our plugin registration tool stopped working for Dynamics 365 9.0 or online trial version. Can need to download new plugin registration tool either from Nuget. or download from below link.
 Plugin Registration 9.0

Thursday, 3 May 2018

Dynamics 365: Generic Assembly


Dynamics 365 extended their capability with help of workflows and actions.
Even we can create UI workflows in Dynamics 365 easily. But still we need custom workflows, plugins and action to meet user requirements.
To create any custom workflows, plugin we need knowledge to .net and any supported language like VB or C#.
To meet this requirement, we are trying to create a generic assembly which can be used by any organization without any cost and development.
You just need to download this solution and install in your organization and start using it.



Currently, this assembly contains below features. In future we are going to enhance their feature count in upcoming new versions.
You can also share your feedback and generic feature to added in comment section.



Features: -

CheckUserInTeam: -
This feature is created as custom workflow. If you want to check specific user present in specified team or not this workflow can be used.
Working: - This workflow contains Two Input parameters named User(System user lookup) and Team(Team lookup)  and One output parameter named IsAvaliable (Boolean).
You need to provide value in User and Team lookup and this workflow will check is user present in given team or not and return result in true or false in IsAvaliable output parameter.

SendEmailToQueueMember:  -
This feature is created as custom workflow. Currently in Dynamics 365 do not have any out-of-box option to send email to queue members.
 So, if you want to send email to all Queue member this workflow can be used.
Working: - This workflow contains Two Input parameters named Queue (Queue lookup) and Email (Email lookup).
You need to provide value in Email and Queue lookup. You can use OOB workflow to create email and then use this custom workflow to send email to all queue member. In this custom workflow we are retrieving all queue members and adding to email “TO” list then custom workflow will send this email via code.
















Make sure all queue members have valid email Id. And email have valid value in email “From” attribute.



GetUserTeam: -
This feature is combination of System Action and Plugin. Currently in Dynamics 365 we can retrieve current user roles using Javascript.
Xrm.Page.context.getUserRoles()
But we do not have any option to get all teams of specified user.
 So, if you want to get all Teams to specific or current user you can use this feature.

Working: - This workflow contains One Input parameter named User (System user lookup) and One Output parameter named UserTeam (Team EntityCollection)
As we know entity collection parameter is not allowed System or Custom workflow But Dynamics 365 allow use “EntityCollection” in Action process.
So, We have created one Action that will take user as input parameter and return Team as entitycollection.



This action will call our plugin code that will retrieve Team for given user.

Limitation: - You can’t call this action from System workflow because it contains entityCollection argument which is still not supported by workflow. May be in future release Microsoft allow entitycollection in workflow also.

So, You need to call this Action from Javascript Code.

In given Solution you will find a webresource named “sav_/scripts/jswr.js” that have function “GetTeam” Which you can use to call this action. In result “Team Name” and “TeamId” is displaying in browser console. You can add your required code there.


Click on Follow to be update about my new blogs.











Friday, 27 April 2018

Dynamics CRM: Chrome Console


Declaration: - This article is only for learning purpose. Use these articles only in development environment. I am not prompting this to use in any production environment.
This article only for CRM developer. I am not prompting this to use by any end customer.



Problem: - As a developer some type we do not remember each, and every function given by XRM library or some time syntax not correct. We can find many options to add XRM intellisense in for visual studio. XRM Intellisense
But some time if we do not have access to visual studio? And these intellisense are not updated automatically when our Dynamics CRM versions are update and we are not aware about new function added or removed by Microsoft.
Or If there is any beginner who not aware of function present in XRM Javascript library.



Solution: -
As we aware Chrome give better performance for Dynamics 365 as compared to Internet Explore.
Here, I am going to introduce one another great feature of Chrome that is “Console”. We mostly use console.log(“our message”) in Javascript to write information or error that can help us later.
But we can also use Chrome Console option to use XRM intellisense.



Steps: -
  1. Open your development Dynamics CRM environment. Navigate to any CRM record. I am taking case record for example.
















2.Go to form property and add a function onSave event. That function need to have debugger; so our Chrome Debugger tools can work.

















3. I am using a sample function which only contain debugger statement.
function test()
{
debugger;
}
If debugger is not written in our code, we will receive real time or property will return null.
4. Publish your changes and refresh your record page (Press Ctrl+ r)
Now we are ready to use Chrome Console.
5. Press F12 or Ctrl+ Shift + I or using Chrome tools option to open developer tool.




















6. Now Click on save button this transfer control to Developer Tools.

















7. Go to “Console” tab of developer tools.

When you start typing X it intellisense will start working. As in below image I have entered Xrm.Page.ge

It starts showing all available functions.
















Even we can check how our code will behave same as written in Javascript file.

In my example I am using Xrm.Page.getAttribute('description') function. When you click on _proto_: link it will start showing all the method available to “getAttribute” method for field type “Single line text”















You will also see some additional method for “Lookup” attribute which is normally not shown in any intellisense.



















Even when you use make any change it will show real time. I am going to change attribute required level using this.
Without My code











After using code: -
 Xrm.Page.getAttribute('description').getRequiredLevel('required')










We have changed form behavior without writing any code in our Javascript file. So, we can use intellisense and real time code impacts.
This Console can also override Dynamics 365 customization. But this will not breach field level security field, which is great.

Example: - There is one “Read-Only” field on form which cannot be update by user. But with this cheat code allow you to update “Read-Only” field also. 













Use this feature only for development and testing.

Monday, 16 April 2018

Dynamics CRM : Bulk Execution Workflow


Bulk Execution Workflow

Case Study: -
Some time we need to run on demand workflow for selected set of records. This task need manual intervention.  In some scenario we want to schedule this task on hourly basis or daily basis. In Dynamics CRM there is no provision for scheduling on demand workflow execution for set of selected records. Like Dynamics CRM provide provision to schedule Bulk deletion workflow scheduling.

Solution: -

In below solution I will provide a way how we can schedule our bulk on demand workflow execution.
I have used below one custom entity to schedule bulk workflow execution.

Entity Name: -Bulk Execution Task
Below are the field used in this entity: -

Field name
Data Type
Fetchxml Query
 Multiple Lines of Text
Last Run Time
Date and Time
Next Run Time
Date and Time(Calculated)
Repeat Duration(Hours)
Whole Number
Termination Date
Date and Time

Calculated field: -
















Workflow Used: -

In this solution a OOB workflow is used name “Bulk Workflow Execution”.
This workflow will trigger when record is created in “Bulk Execution Task”.

















In this workflow Child process needs to check.
If record is created and conditions are meet a custom workflow will execute. This custom workflow responsible to run our on-demand workflow based fetch query we have specified.
























You can download solution from here: - Download Here

This solution is created in “Dynamics 365” version.


Working: -

Create record in Setting->Bulk Execution Workflow->New.
Provide workflow ID.
Open your workflow need to execute and copy ID from address bar. Make sure On-demand is checked for this workflow.












Provide your fetch XML query to select records. You can used “Advance Find” to get fetch query.
Provide other details.















When you save the record. Your Workflow start execution based on your information.

Click on follow to keep update from my blogs.


Field Security Profile - Based on Owner

 Recently received requirement related to Field security profile. Expectation : - 1.       Set to users need access of secure attributes. 2....

Test