Friday, 16 October 2015

CRM 2015 Online Update 1 - {Javascript Code Example #3} - Sub-grid controls new events and objects

 With Update 1 for CRM 2015 Online more events and objects are available, before this update, only the refresh was available. 

Now it is possible to interact with grid-controls to get the number of total records, getting the object grid so can be worked as an object, it is possible as well to get all rows or even selected rows from the grid only.

I would say that mostly i would use the grid object on the purpose of getting either all rows or selected rows, however it is possible to extend to more functionalities.

As an example i leave below few lines of code to access the grid from javascript:

Iterating trough the grid as an array:

 var allGridRowData = []; 

var rows = Xrm.Page.getControl("Contacts").getGrid().getRows();

 rows.forEach(function (row, i) { 

    allGridRowData.push(row.getData()); 

});

Hope it helps.

Friday, 4 September 2015

CRM 2015 - UI - 'Save' and 'Save and Close' Buttons Behaviour

I was having a strange behaviour from one to another environment related to the 'Save' and 'Save and Close' buttons, however, never had the opportunity to check why i could see in DEV and not in UAT.


Today i have figured out, and it is so easy that i couldn't believe, and probably most of you know, if you don't here it goes.

Having the 'Auto Save' Enabled on the System Settings causes that. 

Hope it helps.

Tuesday, 5 May 2015

CRM 2015 - {Javascript Code Example #2} - Save a form asynchronously with call back function

 If for any reason you need to have a call back function in CRM after saving a form asynchronously it is possible to do with this line below:


Xrm.Page.data.refresh(save).then(successCallback, errorCallback); 

More detail please see next table:


Name Type Required Description 

save 

Boolean 

No 

true   if the data should be saved after it is refreshed, otherwise   false 

successCallback 

Function 

No 

A function to call when the operation succeeds. 

errorCallback 

Function 

No 

A function to call when the operation fails. 

An object with the following properties will be passed: 

  • errorCode   Number . The error code.

  • message   String . A localized error message. 


Src:

https://msdn.microsoft.com/en-us/library/dn481607.aspx 

Tuesday, 28 April 2015

CRM 2015 - Javascript - {Personal Opinion #1 - Considerations on customizing CRM Forms}

 Extending a lookup control for people that have been working with CRM sometimes looks like a nightmare, and why? 


The reason for this is related with upgrades, I remember for instance that form CRM 3.0 to CRM 4.0, the way our development team was using this functionality on upgrading it would break the custom filtering.


Honestly, i'm not the kind of guy that likes to extend to much the CRM in terms of Javascript because of many reasons, i'm not saying i don't customize, but i think in very single detail, what are the consequences of doing everything, before doing it.


Usually everything gets clear to me when i think on the word "Upgrade", if i think:

Ok, i can do this in 2 hours instead of spending 8 hours, however, in the future i will be in trouble because it can break, i prefer to be honest to the customer and say what i think is the best in here.


Sometimes, the last sentence in CRM is more clear for people with years of experience in the product, because we got already so many hours trying to fix things that were Out of The Box that from one minute to the other with no reason just stop to work. 


In here i will spend few more hours because it is my work that's on the spotlight.


Now everything is much better in terms of the framework provided from Microsoft to customize the forms, it is possible using that framework to control almost every type of control (field, web  resource, grid,..) that is indeed a big help for us developers.


I will leave in here the word Encapsulation, in few words is: "Packing of data and functions into a single component.", and why? Because if instead of doing methods without thinking of reusing them, is already as headache, if something breaks and you have to fix in every single location you are using that piece of code, so, every time i need to do something i think, am i seeing to use this in more than one place? If yes, ok, lets create a function in a common file. 

With this approach, if something needs to be changed in that functionality, you need only to change in one place. 


Hope it helps.

Tuesday, 21 April 2015

CRM 2015 Online 2015 Update 1 - Optimistic Concurrency

 How many times were you been asked by a customer the following?

If 2 users open the same record, what will happen in terms of database.


The answer would be simple. Last update wins. It means, the data that will be saved by last will win.


Now, reading MSDN, i can see that probably with the Update 1 to the Online we will be able to control that.

If we create a Pre-Plugin for the Update Message on the entities we will need to detect if someone or something updated the same record,from the moment we opened until the moment we are updating. 

The fields we can use for that are:
  • ConcurrencyVersionMismatch 
  • RowVersion

More information on this subject, please have a look on the MSDN page while i can't do myself some tests to understand better how this works.


Hope it helps.

Saturday, 18 April 2015

CRM 2015 - {Javascript Code Example #1} - Grid Objects and Methods

 When we need to extend the Grids trough Javascripts, we should use the client sdk to avoid problems in the future, not only because of upgrades, but as well update rollups.


Reading an article from MSDN, found written that only the refresh method was available, what means other extensions were not "supported". 


This few examples are can applied to a CRM 2015 Online Organization with Update 1. Hope that it can be available as well for OnPrem near in the future.


1. Getting the Grid Control, and it was already working previously:

var contactsSubgrid = Xrm.Page.getControl("Contacts");

2. Add an event on load:

var myContactsGridOnloadFunction = function () { console.log( "Contacts Subgrid OnLoad occurred" ) }; 

Xrm.Page.getControl( "Contacts" ).addOnLoad(myContactsGridOnloadFunction);

3. Get all rows:

var allRows = Xrm.Page.getControl( "Contacts" ).getGrid().getRows(); 

Source of the code:


I will do more examples with this, and write a new version of tested methods and results.

Hope it can help.

Thursday, 16 April 2015

CRM 2015 - Perform specialized operations using Update

Functionality now available on release of new sdk release (7.1.a ,March 2015)

Before this release, some specialized messages should be called to update some entity fields, methods like assign request or set state request.


However, from this release on it would be able to be done from the Update message. 


Please see the below table to see what are the deprecated methods.


Deprecated message request Attribute to update 

AssignRequest 

<entity>. OwnerId 

SetStateRequest 

<entity>. StateCode 

Important 
For   SLA   and   RoutingRule   entities, changing the   OwnerId   and   StateCode   in a single   Update   message invocation is not supported and results in an exception. 

SetParentSystemUserRequest 

SystemUser.ParentSystemUserId 

SetParentTeamRequest 

Team.BusinessUnitId 

SetParentBusinessUnitRequest 

BusinessUnit.ParentBusinessUnitId 

SetBusinessEquipmentRequest 

Equipment.BusinessUnitId 

SetBusinessSystemUserRequest 

SystemUser.BusinessUnitId 

*<entity> refers to any entity that provides this attribute. 

Source of the information:

https://msdn.microsoft.com/en-us/library/dn932124.aspx 


Hope in helps.

Wednesday, 15 April 2015

CRM 2015 - Microsoft.Xrm.Sdk - UpsertRequest Class

 New method available for the purpose of integration, at least is the reason Microsoft is saying for the availability of this class, and as well in the article says:

[This topic is pre-release documentation and is subject to change in future releases.] 

Warning

For Microsoft Dynamics CRM Online organizations, this feature is available only if your organization has updated to Dynamics CRM Online 2015 Update 1. This feature is not available for Dynamics CRM (on-premises). 


I see good value in here for integration purposes of course, instead of using a Retrieve to see if a record exists or not, and after using the CreateRequest or UpdateRequest methods according if the record exists or not, you will be able to use the UpsertRequest.


In terms of development it will decrease, and i would say that it is a big help, however as Microsoft says, please don't use this always, it has a cons of course, it is a heavier  operation, because inside it is doing the retrieve, and create or update after.


So, for now it will be available in Online and not On Premesis, lets have the fingers crossed for having as well in On Premesis.


Source is below:

https://msdn.microsoft.com/en-us/library/dn932135.asp

Tuesday, 14 April 2015

CRM 2015 - Microsoft.Xrm.Client DLL - Round DateTime To

 Having a look on my CRM Bible (SDK), i have found a Enumeration to Round Dates to: Day, Hour, Minute, Second and Month. So, i had to test that.

Always good to know this things, instead of doing extra lines of code or using other libraries for this, why not using default capabilities of CRM dlls.

DateTime dt = Microsoft.Xrm.Client.DateTimeExtensions.Round(DateTime.Now, Microsoft.Xrm.Client.RoundTo.Day);


Result will be:{15/04/2015 00:00:00}


Hope it helps.

Monday, 13 April 2015

CRM 2015 - Customizations - Change CSS

 Before staring to tell what was happening to me, i have to say I'm the first to say to avoid this kind of customizations, however and because of a need i had to do this.


I needed to add a border to the fields in a form even if they were not with the focus on them. So, the only way of doing that is applying some kind of CSS to them, i found some articles and i have chosen the below one.


 function load_css_file(filename) { 

 var fileref = document.createElement("link"); 

 fileref.setAttribute("rel", "stylesheet"); 

 fileref.setAttribute("type", "text/css"); 

 fileref.setAttribute("href", filename); 

 document.getElementsByTagName("head")[0].appendChild(fileref);

}


function customizeFormsCss() { //inject css file to the header load_css_file("WebResources/ttt_CRM.CSS.FormCustomization"); 

}

Now, it comes the funny part that made me waist a lot of time. A colleague just started to do the developments, and it was working in his laptop (IE and Chrome), however it was not working in mine. So, the next thing that i did was, lets import to a new organization, and in my laptop started to work.

So, after hours and because i deployed as well to a VM, into two different organizations, and it was working perfectly. 

After digging a little bit more, and because with this i taught that only could be something related to a configuration in the Organization, i discovered the reason. :)

In the one that it was not working, i have selected the below check box, after not selecting it started to work.

Hope to help more people with this.

Sunday, 12 April 2015

CRM 2015 - Javascript - Opening a Web Resource

 Javascript function from the Namespace Xrm.Utility that can be called to open a Web Resource with the possibility of adding parameters. Bare in mind that cannot that this function will not work with Microsoft Dynamics CRM for tablets.   

Xrm.Utility.openWebResource(webResourceName,webResourceData,width, height) 

Parameters 

  

Name Type Required Description 

webResourceName 

String 

Yes 

The name of the HTML web resource to open. 

webResourceData 

String 

No 

Data to be passed into the data parameter. 

width 

Number 

No 

The width of the window to open in pixels. 

height 

Number 

No 

The height of the window to open in pixels. 

Return Value 

Window object. 

Remarks 

An HTML web resource can accept the parameter values described in   Passing Parameters to HTML Web Resources . This function only provides for passing in the optional data parameter. To pass values for the other valid parameters, you must append them to the webResourceName   parameter. 

Examples 

Open an HTML web resource named “new_webResource.htm” 

Xrm.Utility.openWebResource( "new_webResource.htm" ); 

Open an HTML web resource including a single item of data for the data parameter 

Xrm.Utility.openWebResource( "new_webResource.htm" , "dataItemValue" ); 

Open an HTML web resource passing multiple values through the data parameter 

 var  customParameters = encodeURIComponent( "first=First Value&second=Second Value&third=Third Value" );Xrm.Utility.openWebResource( "new_webResource.htm" ,customParameters); 

noteNote 
These values have to be extracted from the value of the data parameter in the HTML web resource. For more information, see   Sample: Pass multiple values to a web resource through the data parameter 

Open an HTML web resource with the parameters expected by HTML web resources 

Xrm.Utility.openWebResource( "new_webResource.htm?typename=account&userlcid=1033" ); 

For more information, see   Passing Parameters to HTML Web Resources 

Open an HTML web resource, setting the height and width 

Xrm.Utility.openWebResource( "new_webResource.htm" , null , 300,300); 


From MSDN: https://msdn.microsoft.com/en-us/library/jj602956.aspx#BKMK_OpenWebResource 

Hope it helps.

CRM 365 Cloud - Disassociate 2 records using typescript

In case you need to Disassociate 2 records, please find below the code that allows you to do that.      export async function DissociateE...