Monday 17 November 2014

Microsoft free exam vouchers


Microsoft is offering 4 exam vouchers for office 365 and Azure

All voucher can be used until December 31, 2014 and as an limited stock.

Microsoft Certified Specialist in Azure, pass one or both of these exams:
  • 71-532: Developing Microsoft Azure Solutions (beta)
  • 70-533: Implementing Azure Infrastructure Solutions
Microsoft Certified Solutions Associate in Office 365, pass both of these exams:
  • 70-346: Managing Office 365 Identities and Requirements
  • 70-347: Enabling Office 365 Services

You can access promotion is through the following link:

https://vouchers.cloudapp.net/mcp/default.aspx


Thursday 6 November 2014

Change the "Filter on" to all on the Activity Associated views

When we want to see all activities from an account the default value is "next 30 days".

If you want to change the default value there no easy way to do so. One the things it's change it by JavaScript.

Create a new JavaScript web resource and add this code to it:

 //default the Activities 'Filter on' to 'All'  
 function filterAllActivities() {  
   document.getElementById("navActivities").onclick = function () {  
     Mscrm.Details.loadArea(this, "areaActivities");  
     document.getElementById("areaActivitiesFrame").onload = function () {  
       var entityName = Xrm.Page.data.entity.getEntityName();  
       var entity = entityName.charAt(0).toUpperCase() + entityName.substr(1);  
       var doc = this.contentWindow.document;  
       var filterOn = doc.getElementById("crmGrid_" + entity + "_ActivityPointers_datefilter");  
       filterOn.value = "All";  
       var evt = document.createEvent("HTMLEvents");  
       evt.initEvent("change", false, true);  
       filterOn.dispatchEvent(evt);  
     };  
   };  
 }

Add this new JavaScript web resource library to the form properties (from the entity you want exemple: account, case, opportunity, etc), add an event handler in the form "OnLoad" and call the function "filterAllActivities"

Save and publish.

Tuesday 4 November 2014

Dynamically change the user email address when sending emails

When you need that several users use the same email address when sending emails, you can do this with creating a queue, setting the email configuration to that queue and every time an user need to send an email, he can change on the "from" field to the queue.

The problem is sometimes the user forgot to change address and the email is send with the wrong email address or not send at all (the user don't have mailbox configured)

This is a solution to dynamaclly change the email address to the default queue of the user every time you create a new email or reply to an email.

Note: This will change every user to the his default queue.

- Change the default queue of every user to the some default queue.
- Configure and test email sending through this queue.

Now the code:

Need to create 2 JavaScript web resources

new_REST_SDK: You can find the SDK.REST.js on CRM 2011/2013 SDK in SDK\SampleCode\JS\RESTEndpoint\JavaScriptRESTRetrieveMultiple\JavaScriptRESTRetrieveMultiple\Scripts

Use the this code on the web resource text editor

function GetDefaultQueue() {  
   if (Xrm.Page.ui.getFormType() === 1 || Xrm.Page.ui.getFormType() === 2) // new form or update form  
   {  
     //Get GUID of logged user  
     var userId = Xrm.Page.context.getUserId();  
     SDK.REST.retrieveMultipleRecords("SystemUser", "$select=QueueId&$filter=SystemUserId eq guid'" + userId + "'",  
     function (results) {  
       var firstResult = results[0];  
       if (firstResult !== null) {  
         var queueId = results[0].QueueId.Id;  
         var queueName = results[0].QueueId.Name;  
         }  
       var lookup = new Array();  
       var lookupItem = new Object();  
       lookupItem.id = queueId;  
       lookupItem.name = queueName;  
       lookupItem.typename = "queue";  
       lookup[0] = lookupItem;  
       Xrm.Page.getAttribute("from").setValue(lookup);  
     }, function(){}, function(){})   
     function errorHandler(error) {  
       alert(error.message);  
     }  
   }  
 }  

-         Save and publish.

-         After the web resources are inserted, go the email form editor and click in “Form Properties”.

-         Add to the form libraries the 2 web resources you created.




-         On the event handler choose (control: form and event: OnLoad)

-         Click on add and use this parameters




-         Save, close and publish.

Now when you try to send an email with one of the user with will change to the default queue.


Monday 3 November 2014

XML validation error when importing solution

Last week I was trying to import a manage solution into a new Microsoft dynamics CRM 2013 organization and I get the following error:

"The import file is invalid. XSD validation failed with the following error: 'The 'distinct' attribute is not declared."

After digging around the customization XML file from the solution, I found out that one of the user of my company build some custom charts and put the distinct property  into an attribute inside the fetchXML tag.



We contacted the Microsoft CRM support team and asked if it were possible to have a distinct property associated with the attribute tag. After a couple of days this was the reply from them:

I've confirmed internally that using the distinct property at attribute level on fetchXML is not allowed, as proved by the XSD validation schema you got.

On Dynamics CRM SDK we have some FetchXML queries that contains this property and it might be possible that the SDK will be changed to show the correct data that can be used.

We apologize for the situation caused by this, and we suggest you to move the distinct property to fetch tag and to not be used on attribute tag.

The solution to this problem:
  •      Unzip the solution zip file.
  •      Open the customizations.xml file.
  •      Remove or put the distinct= ”true” (only the ones that used with an attribute) into the fetch tag.

  •    Save the customizations.xml file.
  •    Delete the original XML in the zip file and add this new customizations.xml.
  •    Import solution.


Friday 31 October 2014

Generate password and shuffle the characters

In a recent project I had to create a function to generate a password with an exact number alpha characters, numeric and symbols and then shuffle them.

numOfNumericChars (Indicates number of numeric characters);

numOfAlphaChars (Indicates number of alpha characters);

numOfSynbolChars ( Indicates number of symbol characters)

validNumChars (Valid characters for numeric. Default is all characters from 0- 9)

validAlphaChars (Valid characters for alpha. Default is all characters from a- z  and A-Z)

validSymbolChars (Valid character for symbols. Default is all characters in  !-+_@&$#%)

C#
public string generatePassword(int numOfNumericChars, int numOfAlphaChars, int numOfSynbolChars, string validNumChars = "1234567890", string validAlphaChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", string validSymbolChars = "!-+_@&$#%")  
     {  
       StringBuilder res = new StringBuilder();  
       Random rnd = new Random();  
       while (0 < numOfNumericChars--)  
       {  
         res.Append(validNumChars[rnd.Next(validNumChars.Length)]);  
       }  
       while (0 < numOfAlphaChars--)  
       {  
         res.Append(validAlphaChars[rnd.Next(validAlphaChars.Length)]);  
       }  
       while (0 < numOfSynbolChars--)  
       {  
         res.Append(validSymbolChars[rnd.Next(validSymbolChars.Length)]);  
       }  
       string stgPassword = res.ToString();  
       //Shuffle password  
       char[] array = stgPassword.ToCharArray();  
       Random rng = new Random();  
       int n = array.Length;  
       while (n > 1)  
       {  
         n--;  
         int k = rng.Next(n + 1);  
         var value = array[k];  
         array[k] = array[n];  
         array[n] = value;  
       }  
       return stgPassword = new string(array);  
     }  


Thursday 30 October 2014

IOrganizationService

What is IOrganizationService?

Is the web service that accesses data and metadata for your organization. 

Why do I need a IOrganizationService?

You need IOrganizationService when you want to work with data in our Microsoft Dynamics CRM system. The methods available are:
  • -          Create (Create a record of an entity)
  • -          Retrieve (Retrieve a record of an entity)
  • -          RetrieveMultiple ( Retrieve a collection of records of an entity. This can be used with query expression or fetch XML)
  • -          Update (Update a record of an entity)
  • -          Delete (Delete a record of an entity)
  • -          Associate (Create a link between two records)
  • -          Disassociate (Delete a link between two records)
  • -          Execute (Execute a process. The must common is workflows, imports and detect duplicates)


How can I get IOrganizationService?

To get the organization service you need 3 thing:
  • -          User (username of a valid user on the CRM organization)
  • -          Password (valid password for the user)
  • -          Uri (You can get the organization service Uri in your Dynamics CRM system. Go to Settings à Customizations à Developer Resources.)


How can I use it on code?

Need a reference to the microsoft.xrm.sdk.dll from the SDK

C#
//organization url  
 IServiceManagement<IOrganizationService> orgServiceManagement = ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri(“Uri”));  
 //Put Credentials  
       AuthenticationCredentials authCredentials = new AuthenticationCredentials();  
       authCredentials.ClientCredentials.UserName.UserName = “user”;  
       authCredentials.ClientCredentials.UserName.Password = “password”;  
 AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);  
 //connection to CRM  
 OrganizationServiceProxy Service = new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);  
       Service.EnableProxyTypes();  
       IOrganizationService _service = Service;  

First Post


The main idea for this blog is to help others but also take notes for future projects.

I'll triy to insert posts regularly so this blog is updated.