Tuesday 29 September 2015

FormType (Create and Update) based Business Rules in CRM 2015

Hi,

Today I was writing some JavaScript to hide some of the controls and got a doubt that whether we can do the same using Business Rules.

The answer is Yes, we can do. Just check the condition CreatedOn contains data and write your actions.

Note: Make sure you have added CreatedOn field on the form. If you are not using it, hide it form the form. Business rule requires the field to be there on the form.

Hope this helps.

--
Happy CRM'ing
Gopinath

Basic Security Role Privilege for Data Import in CRM

Hi,

Today, one of the users in CRM was unable to import data in CRM. We did check the security role and found that the user doesn't have correct privilege for importing the data.

Here are the basic security role privilege for data import
 
  • Data Import – Except Assign and share we need all the rest user level 
  • Data Map – Except Assign and share we need all the rest user level 
  • Import source file –Except Assign, share and Delete we need all the rest user level 
  • Web Wizard - Read 
  • Web Wizard Access Privilege - Read 
  • Wizard Page - Read

Hope this helps.
 --
Happy CRM'ing
Gopinath 

Wednesday 23 September 2015

Scope of the Workflow in CRM

Hi,
 
Today, I got a question from one of the fresher who started working in CRM on the Scope of the workflow in CRM.
 
User - the Workflow will exclusively run on records with the same owner as the Workflow.

Business Unit- the Workflow will exclusively run on records owned by any user in the same Business Unit as the owner of the Workflow.

Parent: Child Business Units- the Workflow will exclusively run on records owned by any user in the same Business Unit or Child Business Units.

Organization - the Workflow will run on records owned by any user.

Hope this helps.

--
Happy CRM'ing
Gopinath

Tuesday 22 September 2015

Optional and Named Parameters in C# 3.0

Hi,
 
Recently in one of our project we got a requirement to change a method which should be one more parameter. The method is used in multiple places, changing in all places is not the correct approach. Then, we thought of writing over loaded method. Then I just did quick search and came to know about Optional and Named Parameters.
 
Named and optional parameters are really two distinct features, and allow us to either omit parameters which have a defined default value, and/or to pass parameters by name rather than position
 
Optional Parameters - allow us to omit arguments to members without having to define a specific overload matching.
 
Named Parameters - are passed by name instead of relying on its position in the parameter list.
 
Here is the one simple example.

static void Main()
{
      // General Method Calling.
      CheckOptionalAndNamedParameters(6, "Gopinath");
      // with out optional parameters.
      CheckOptionalAndNamedParameters();
      // with out second optional parameter.
      CheckOptionalAndNamedParameters(6);
      // We cannot call the method by skipping the first parameter and passing the second.
      // CheckOptionalAndNamedParameters("Dot");
      // Specify one named parameter.
      CheckOptionalAndNamedParameters(strValue: "Gopinath");
      // Specify both named parameters.
      CheckOptionalAndNamedParameters(intValue: 6, strValue: "Gopinath");
      Console.Read();
}

static void CheckOptionalAndNamedParameters(int intValue = 1, string strValue = "Test")
{
      Console.WriteLine("Integer Value = {0}, String Value = {1}", intValue, strValue);
}

Hope this helps.
 
--
Happy Coding
Gopinath

Monday 21 September 2015

Javascript to get the User Name in CRM 2013/2015

Hi,
 
We used to write soap call method for getting the user name on the form in JavaScript.
We used to get User Id by using the following line.

Xrm.Page.context.getUserId();
Now in the same way, we can also get the logged in user name.
Xrm.Page.context.getUserName();

Use the following code to set the lookup field in JavaScript.

var setUserLoopUp = new Array();
setUserLoopUp[0] = new Object();
setUserLoopUp[0].id = Xrm.Page.context.getUserId();
setUserLoopUp[0].name = Xrm.Page.context.getUserName();
setUserLoopUp[0].entityType = 'systemuser';
// Set the look up field.
Xrm.Page.getAttribute("LookupField").setValue(setUserLoopUp);
 

For more information on Setting and Getting Lookups

Hope this helps.

--
Happy CRM'ing
Gopinath

Sunday 13 September 2015

Microsoft Dynamics 2016 Release Overview and Preview Guide

Hi,

The release preview guide is now available for downloading. This is a preview guide covering the new features of Microsoft Dynamics CRM 2016.

PDF Download

Release Overview Vedio

Hope this helps.

--
Happy CRM'ing
Gopinath

The workflow cannot be published or unpublished by someone who is not its owner

Hi,
 
Today while importing a solution which has workflows we got a below error.
 
"The workflow cannot be published or unpublished by someone who is not its owner"
 
Went ahead and checked the owners of the workflow and found that the owner of the activated process is not the same as the user who is importing the solution.

The fix can be applied by two ways.

a) Import the solution using the user who owns the activated process. This cannot be good solution if there are processes owned by different users which need to be updated by the solution import.

b) Verify the processes that are included in the solution, and then find them in the organization, if they are not owned by you then you must assign them to yourself. You can reassign them to the original user after you import the solution. However, you will have to ask the process owners to activate it after the import.

Hope this helps

--
Happy CRM'ing
Gopinath

Plugin/Workflow to Validate Business Process Flow in CRM 2015

Hi,

Most of the times we get requirement to validate the user on clicking Next stage or previous stage. This can be easily done by workflow.

1) Just create a real time workflow by following the below steps.
2) Select Process Stage (StageId) from Record Field Changes
3) Check the condition from Process Stage, add your conditions here along with the stage you wanted to validate.
4) Stop the workflow with the message.

Output

In my requirement, I wanted to validate some with the current stage and previous stage. Normally for this type of things we go with Plugin by adding a pre-image.

I tried the same to register the plugin, unfortunately the plugin registration tool is not showing any fields that are related to Process
to select in the Filtered Attributes.
However, we have a fix for this.

1) Use Developer toolkit for creating a plugin and registering.
2) Register the plugin on update and select any field whichever you want. I did select 'name' in this example.
 
3) The toolkit prepares Register XAML for you. Now, go ahead and change the field name to stageid and deploy the solution.
4) In the same way, you can also register PreImage and PostImage.

Here is my code in the plugin.

Output

Note: Currently this is working only Online CRM and working on OnPremise with issues like Business Process Flow shows two active stages, after validating users are not allowed to modify anything until they refresh the page etc..

We will have wait for Ara release to get the issue fix. Will update this post soon.

Hope this helps.
--
Happy CRM'ing

Gopinath
 

Thursday 10 September 2015

Sync Account record with out clicking on Submit Button from CRM to Nav

Hi,

Today when I was working on synchronizing data from CRM to Nav using Dynamics Connector came to know that the user need to explicitly click on Submit button to start the sync.

But in our case, user do not want click on Submit button every time and it can be done very easily.

The Submit button updates Ready For Integration value to True. Just do the same using JavaScript and call it on Save of the record. That's it, your record will be automatically synchronized to Nav and user won't see Submit button.

function onSave() {
    Xrm.Page.getAttribute("dynamics_isreadyforintegration").setValue(true);
}

Hope this helps
--
Happy CRM'ing
Gopinath

Wednesday 9 September 2015

OnLoad event is not triggering in a Webresource CRM 2013/2015

Hi,

Today, I did see one good issue.

We have a web resource which is placed on the form and we wanted to have some logic when it loads. I had initially written logic on the "onLoad" event but unfortunately it was firing.

The fix is simple, just write your logic inside document.ready event instead of load event.

Here is the syntax for it.

$(document).ready(function () {
    console.log("I am ready");
});

Make sure you add Jquery reference inside the web resource.

Hope this helps.

--
Happy CRM'ing

Gopinath

Tuesday 8 September 2015

You do not have permission to run the 'Design, Codeunit, Basic' System. Contact your system administrator to have our permissions changed.

Hi,

Today when I was try to open CodeUnit in the Nav Development Environment and got the below error.

The reason for it is I don't have Dev License Key.

Here is the way to upload you license key once you get it.

Open Nav Development Environment.
Go to Tools and License Information.
You will see button to Upload or Change the key.

Hope this helps.

--
Cheers
Gopinath

 

Refresh ribbon using javascript in CRM

Hi,
 
Most of the times, we write some EnableRules for hiding and showing some buttons based on the Form values.
 
The button renders properly when it is loaded and when user changes some data on the form then if we need show/hide the field, we can use RefreshRibbon method.
 
Here is the syntax of it.

Xrm.Page.ui.refreshRibbon();

Just call this line on the Change event of the field.

Hope this helps.

-- 
Happy CRM'ing
Gopinath

Show or hide 'Add New' or '+' button on form sub-grid based on the value on the form

Hi,
 
Today I got a requirement to Hide/Show "+" button on the Sub grid based on some conditions.
 
I used Ribbon workbench for doing it. But, unfortunately it was not working. After some search came to know that I am trying to customize wrong button. Actually, we should apply our commands on the highlighted button.
Here are the steps to be followed for hiding and showing the button.
 
Create a Webresource and write you condition in it. Make sure it returns True/False.

function EnableNewButton() {
    return true;
}

Create a solution in CRM and add the required entity and webresource.
Open the same solution in Ribbon Workbench.
Right-Click on the button and click Customize Command.
Its shows all the existing Command rules like Display rules, Enable rules etc..
Right click on the new customized command and click Edit Enable Rules.
Click on Add New button and Select Custom JavaScript Rule.
Change the Id if you wish and Click on Add Step
Select Custom JavaScript Rule.
Select the WebResource and Javascript function name.
Click on Publish.

Done, now the button will be hidden/shown based on the Boolean value that is returning from the JavaScript function.

Hope this helps.
 
--
Happy CRM'ing
Gopinath 

Friday 4 September 2015

SoapLogger to generate a Request XML in CRM 2013/2015

Hi,

Normally, we feel the pain if there is something to be written in JS like generating the request XML for Create, Update, Assign, SetStatus, Calling an Action etc.

Product team understood our pain and gave a tool for generate the request XML.

Here are the steps for it.

1) Download SDK and Extract it.
2) Goto SDK\SampleCode\CS\Client\SOAPLogger.
3) Open the solution in Visual Studio
4) Open SOAPLogger.cs
5) Add the code which you want to execute as below.
6) Go to the bin folder of the project.
7) You will see a text file created with name as output which will has both request and response.
You can follow the same procedure for generating any request XML in CRM.

Hope this helps.
--
Happy CRM'ing
Gopinath

Call Actions from Javascript/C# in CRM 2013/2015 and Trigger a plugin

Hi,

Today we got a requirement to call a Plugin on click of Custom button.

First we thought of updating a field in the record and register a plugin on that field update. After some search I came to that we can trigger a plugin on execution of Action and also we can execute the Action from Javascript.

Follow the below steps to implement this.

Create a blank Action name Trigger Plugin.
Open Plugin Registration Tool and Register a plugin which you want to execute.
Create a step and give the message as Action Name.

That's it, you are done.
When you execute a Action, you will the plugin is triggered.
One more good thing is we can call the Action from JavaScript and also from C#.

C#
OrganizationRequest orgReq = new OrganizationRequest("new_TriggerPlugin");
orgReq["Target"] = new EntityReference("account", new Guid("01DC64CE-0752-E511-80D8-000D3AA023B6"));
OrganizationResponse response = iService.Execute(orgReq);

JavaScript
function CallAction() {
    var accountId = Xrm.Page.data.entity.getId();
    var entityName = "account";
    var requestName = "new_TriggerAction";
    ExecuteAction(accountId, entityName, requestName);
}

function ExecuteAction(entityId, entityName, requestName) {
    // Creating the request XML for calling the Action
    var requestXML = ""
    requestXML += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
    requestXML += "  <s:Body>";
    requestXML += "    <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
    requestXML += "      <request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
    requestXML += "        <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
    requestXML += "          <a:KeyValuePairOfstringanyType>";
    requestXML += "            <b:key>Target</b:key>";
    requestXML += "            <b:value i:type=\"a:EntityReference\">";
    requestXML += "              <a:Id>" + entityId + "</a:Id>";
    requestXML += "              <a:LogicalName>" + entityName + "</a:LogicalName>";
    requestXML += "              <a:Name i:nil=\"true\" />";
    requestXML += "            </b:value>";
    requestXML += "          </a:KeyValuePairOfstringanyType>";
    requestXML += "        </a:Parameters>";
    requestXML += "        <a:RequestId i:nil=\"true\" />";
    requestXML += "        <a:RequestName>" + requestName + "</a:RequestName>";
    requestXML += "      </request>";
    requestXML += "    </Execute>";
    requestXML += "  </s:Body>";
    requestXML += "</s:Envelope>";
    var req = new XMLHttpRequest();
    req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", false);
    req.setRequestHeader("Accept", "application/xml, text/xml, */*");
    req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
    req.send(requestXML);
    //Get the Resonse from the CRM Execute method
    var response = req.responseXML;
}

You can use SoapLogger to generate request for you. Follow the link to know How to use SoapLogger

Hope this helps.

--
Happy CRM'ing
Gopinath

Get the Stage and Process of the Business Process

Hi,

Today we got a requirement to do some action based on Opportunity Stage.
 
Even though there is a field as stepname on the Opportunity entity. I see that field is not updated all the times. So, here is the C# code for knowing the Stage of the record.
 
string strStageName = string.Empty;
// Get StageId, ProcessId of the record.
QueryExpression objQueryExpr = new QueryExpression("opportunity");
objQueryExpr.Criteria.AddCondition(new ConditionExpression("opportunityid", ConditionOperator.Equal, "<OpportunityId>"));
objQueryExpr.ColumnSet = new ColumnSet(new string[] { "stepname", "stageid", "processid" });

EntityCollection entColProcessStages = iService.RetrieveMultiple(objQueryExpr);
// Query Process Stage by passing StageId and get the name of the stage.
QueryExpression objQueryExpr1 = new QueryExpression("processstage");
objQueryExpr1.Criteria.AddCondition(new ConditionExpression("processid", ConditionOperator.Equal, entColProcessStages.Entities[0].Attributes["processid"]));
objQueryExpr1.ColumnSet = new ColumnSet(true);
entColProcessStages = iService.RetrieveMultiple(objQueryExpr1);
if (entColProcessStages != null && entColProcessStages.Entities.Count > 0)
{
     strStageName = entColProcessStages.Entities[0]["stagename"].ToString();
}

Hope this helps.

--
Happy CRM'ing
Gopinath