Tuesday 31 March 2015

Call External Web Service using Custom Action in CRM 2013/15


In this article, I am providing an example of how actions can be used to make a request to a web service outside of the CRM domain from a record’s form event.

Scenario

Agents need to capture the temperature of City on Case form based on City selected on City Field. In order to do so, we decide to create a button on the command bar that agents can click on and that will perform the following tasks:


  • Read the City and Country information from the form
  • Call an Action that - 
  • Takes the City and Country as parameters
  • Use an external web service to get the temperature in the city
  • Returns the temperature as output parameters
  • Sets the temperature field value on the form
Note: In order to achieve this directly with JavaScript, performing Step 2 of the action would require to make a cross-domain call from JavaScript.

Process Configuration

To start things off, let’s start be creating an Action of type process. This action will have 2 input values (City and Country) and 2 output values (Temperature in Fahrenheit and in Celsius).


The steps are really simple. The action needs to a custom workflow activity that will connect to a weather web service and return the temperature in two output values of its own.













Custom Workflow Activity

Here you can see what the custom workflow activity code looks like. It’s very straight forward in that it only has 3 steps:


  1. Read the city and country inputs
  2. Initialize the web service client object and make the web service call
  3. Set the values back in the output fields to be available in the process















Calling Action from JavaScript



This is the last piece of the puzzle. At this point, we simply need to call the action created from a JavaScript event (ribbon button clicked, on change of a value etc.). In order to achieve this, create a function that is called when the client even occurs. That function should execute the Action, read the output values and set the field values on the form. This has to be done with a SOAP call. There are two ways to do this. 

You can:

Use below link to call Custom Action using Javscript-


Hope this help.

Monday 30 March 2015

How to Enable/Disable users in Dynamic CRM Online

Enabling and Disabling of users in Dynamic CRM On-Premise is not a very tough tasks. Anyone have admin rights can easily select the users from User grid view and Disable it by clicking on Activate/Deactivate button to Enable/Disable the users.

But In Dynamics CRM Online, you won't find Enable / Disable button for System User Records because the Users are monitored through Office365 Portal.

If you have added Users through Office365, then you need to Assign / Remove the CRM License in order to make them Enable or Disable in Dynamics CRM.

So here is the step by step process to Enable/Disable Dynamic CRM Online Users :

Step 1 -

Here you can see I have 4 users in CRM 2015 online organisation and I want to disable one user named 'Suresh Raina'.

Step 2 -

 Login to Office 365 Admin Portal using below Link :
https://portal.office.com/admin/default.aspx#
 Enter CRM online Admin Credential and Login into account


Few of yours might get below error while accessing Office 365 Admin Portal -


This error usually come when you don't use correct URL to access the Office 365 Portal, In some of article/blog you will found the incorrect url to access Office 365


Step 3 - 

After Logged in into Office 365 Portal , you will see Users > Active Users in Left Navigation pan as below





Step 4-

Click on Active Users to see all Enable/Disable users of your CRM Online Org





Step 5 -

Select any one users(Suresh Raina) you want to disable by clicking on Checkbox as shown below



Step 6 -

On the selection of users you would see a new navigation in right side of window
Click on 'Edit'

Step 7 - Uncheck the checkbox 'Microsoft Dynamic CRM Online Professional' to remove the license of user or to disable the user as shown below



Step 8 -

After Clicking on Save Button user will no longer Enable for CRM.
Login to CRM online organisation to check user Status 


As you can see user(Suresh Raina) has been reached to Disable Users View

Friday 27 March 2015

How to change display text of a lookup field in Dynamics CRM 2011/13/15 using JavaScript


Usually when we select a value in a lookup field it displays the Primary Name Field in the text after selection. However it holds the PrimaryIDField in the background.

While working on a requirement a need arise to display a field in the LookUp display which is not a PrimaryNameField.

Let's consider the Order Lookup field here on Case Form. 

Requirement :


Display OrderNo in the display field instead of the OrderName (Which is a PrimaryNameField) in every Order Lookup.
(I have implemented this requirement in CRM 2015)


Before Using Javascript Lookup field Display text will look like below :



Javascript :

Pass Lookup Field as Parameter (I had passed "new_orderno" as fieldname parameter)
Put this Javascript on 'onchange' event of lookup field-

//Change Lookup Display Text

function ChangeLookUpDisplayValue(fieldname)
{
var lookupData = new Array();
var lookupItem= new Object(); 
var lookup = Xrm.Page.data.entity.attributes.get(fieldname);

if(lookup!=null)
{
var displayvalue='';
var xmlText='';

xmlText+="<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";xmlText+="<s:Body>";
xmlText+="<Retrieve xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
xmlText+="<entityName>salesorder</entityName>";
xmlText+="<id>"+lookup.getValue()[0].id+"</id>";
xmlText+="<columnSet xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
xmlText+="<a:AllColumns>false</a:AllColumns>";
xmlText+="<a:Columns xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">";
xmlText+="<b:string>ordernumber</b:string>";
xmlText+="</a:Columns>";
xmlText+="</columnSet>";
xmlText+="</Retrieve>";
xmlText+="</s:Body>";
xmlText+="</s:Envelope>";
var xHReq = new XMLHttpRequest();


var url=Xrm.Page.context.getClientUrl()+"/XRMServices/2011/Organization.svc/web";
xHReq.open("POST",url,false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Accept","application/xml,text/xml,*/*");
xHReq.send(xmlText);

//Capture the result. 
var resultXml = xHReq.responseXML; 
var varray = new Array();

//Check for errors. 
var errorCount = resultXml.selectNodes('//s:Fault').length;
if(errorCount != 0) 
{
var msg = resultXml.selectSingleNode('//faultstring').nodeTypedValue;
alert(msg); 
}
else

var result = resultXml.getElementsByTagName("a:KeyValuePairOfstringanyType");
if(result.length>0) 
{
displayvalue= result[0].childNodes[1].lastChild.text;
}
if(displayvalue!='')       

lookupItem.name = displayvalue;
lookupData[0] = lookupItem;
lookup.DataValue = lookupData;
Xrm.Page.getAttribute("new_orderno").setValue([{id:lookup.getValue()[0].id,name:displayvalue,entityType:"salesorder"}]);
}
}
}
}

After Putting Above Javascript Lookup display text will look like below :





Wednesday 18 March 2015

Celebrating One Year Completion of Blogging





Happy 1 year anniversary of blogging to me !!!

That’s right, one year ago today I started my blog with a single welcome page.

Exactly one year ago, the 18 of March 2014, I was hitting the button “Publish” for the first time! At the time I didn’t really know what I was doing. My only desire was to talk about my technology and "Share What I Know" that also became the Tag Line of my Blog.

A year later the blog has 37 posts, 2,524 total views. Being a non writer I’m proud of myself for being able to stick with it, and I’m excited to keep it going. And On this Day I also would like to promise that I'll try my best to provide you guys the best content of every topic as much as possible.

Thank you all for being a part of my journey !!!

Happy CRMing and Keep Reading...? /A\/S\
Think Dynamic, Do Dynamic


Monday 16 March 2015

Find/Fetch Notes of an Entity in Dynamic CRM 2011/2013

So many times we might have require to find or to fetch attached Notes of  a particular Entity. We can done this either using Plugin code or Javscript code.
Here I am going to share JavaScript code to perform the same :
Take a look -

function CheckNote()
{
try
{
var entityId = Xrm.Page.data.entity.getId();
alert(entityId);
var serverURL = Xrm.Page.context.getClientUrl()+"/XRMServices/2011/OrganizationData.svc";
alert(serverURL);

if(entityId)
{
var oDataQuery = serverURL+"/AnnotationSet?$filter=ObjectId/Id eq guid'"+entityId+"'";
alert(oDataQuery);
Xrm.Page.getAttribute("spousesname").setValue(oDataQuery);
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: oDataQuery,
beforeSend: function (request) { request.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, request)
{
if(data.d.results.length > 0)
{
alert("Present");
}
else
{
alert("Not Present");
}
},
error: function (request, status, exception) { }
});

}
}
catch(e)
{
alert(e.message);
}
}


Hope this will help someone to find or retrieve Notes of an entity.

Friday 13 March 2015

Dumps of Microsoft Dynamic CRM Certifications 2011/13

We are all well aware that a major problem in the IT industry is that there is a lack of quality study materials. 
This Blog provides you everything you will need to take a certification examination and Exam Preparation Material . Like actual certification exams, our Practice Tests are in multiple-choice (MCQs) Our Microsoft MB2-700 Exam will provide you with exam questions with verified answers that reflect the actual exam. These questions and answers provide you with the experience of taking the actual test. High quality and Value for the MB2-700 Exam:100% Guarantee to Pass Your Microsoft Dynamics CRM exam and get your Microsoft certification.

Here is the link from where you can download some most asked questions in MB2-700 Exam which will help you out to become a Microsoft CRM Certified.
https://onedrive.live.com/redir?resid=E596E7F6E13A3700!768&authkey=!AMOrM6Bpr6gSM8I&ithint=file%2crtf

Here are the dumps of MB2-703(Microsoft CRM Customization and Configuration)
https://onedrive.live.com/redir?resid=E596E7F6E13A3700!770&authkey=!ABTV1Grqvedx2mU&ithint=file%2cdocx


Dumps of Microsoft CRM 2011 Certification (Application and Customization both) -
MB2-866 & MB2-868
https://onedrive.live.com/redir?resid=E596E7F6E13A3700!769&authkey=!AMk9qNht9lCMk2U&ithint=file%2crar



Happy CRMing...All the Best

Tuesday 3 March 2015

Dynamic CRM 2013 - Calling Custom Action using Javascript

Before reading this blog I would like to request reader to go through with below post to make clear understanding of Custom Actions or Why should I use Custom Action ;

http://arpitmscrmhunt.blogspot.in/2015/02/crm-2013-advantages-of-using-custom.html


One of the most powerful features introduced in CRM 2013 is Actions. It strongly supports the concept of XRM platform. Actions are the Custom messages which can be created for any entity or globally to perform business operations like create/update/Assign etc. (more than what a Workflow can do). Looking first time we get a feeling that it is very similar to Workflow but hold on it’s very different from WF’s or Plugins.

Below are the key points which make it different:

  • Can be associated with single entity or globally.
  • Actions support Arguments – Input and Output Arguments.
  • Can be only called through web service calls – either JavaScript/Plugins/Web through API calls.
  • Supports Rollback and executes in real time.
  • Always runs under the context of the calling user.


Arguments

Arguments are the parameters or the variables which can be used while creating the action. There are two kinds of arguments

 Input Arguments:

These are the parameters which need to be passed during action call. These can be Optional/Mandatory. For Mandatory argument it is necessary to provide some value while calling this action. These input arguments can be used as variables while performing any operation in the action.

Output Arguments:

These are the parameters which can be returned when the action is called. These can be Optional/Mandatory.

Custom Action can be call through Javascript, Plug-Ins, Custom Workflow, WebServices etc

Today I am going to share a very simple example in which I'll Call Custom Action using Javascript. In my next post i'll also share details of how it is call from Plugins.
Let's take a look the example below in which I am calling Custom Action using Javascript by passing a Input parameter to custom action. Have a look-

Requirement -
I have to update or put any message on 'Case Description' field of case Entity using Custom Action.

Step 1 -   Create a Custom Action (Setting > Process > Action) and Create one Input Parameter which I'll pass from Javascript while calling Action :
I am creating this Custom Action for Case Entity as shown below-
                     
Create Custom Action















Step 2 - Put this Input Parameter in Case Description field to Update the same using Javascript as shown below :

Add Step 'Update Record'















Pass Input Parameter to Case Description field






















Step 3 -  Activated the Custom Action then our Custom Action Creation Step has completed.

Activate the Custom Action


























Step 3 - Add below Javascript code on Case 'OnSave' Event -


function CallActionFromJavaScript() 
{
var actionInputValue = "Custom Action has been executed successfully using Javascript";
var entityId = Xrm.Page.data.entity.getId();
var entityName = "incident";
var requestName = "new_CallCustomAction_Javascript";
try
{
ExecuteActionCreateProject(actionInputValue, entityId, entityName, requestName);
Xrm.Page.data.refresh();
}
catch(e)
{
alert(e.message);
}
}

function ExecuteActionCreateProject(actionInputValue, entityId, entityName, requestName) 
{
try{
    // 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:KeyValuePairOfstringanyType>";
requestXML += "<b:key>ActionInputValue</b:key>";
requestXML += "<b:value i:type=\"c:string\" xmlns:c=\"http://www.w3.org/2001/XMLSchema\">" + actionInputValue + "</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",GetClientUrl(), 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
}
catch(e)
{
alert(e.message);
}
}

function GetClientUrl() 
{
if (typeof Xrm.Page.context == "object") 
{
clientUrl = Xrm.Page.context.getClientUrl();
}
var ServicePath = "/XRMServices/2011/Organization.svc/web";
return clientUrl + ServicePath;
}

Step 4 - Test Custom Action by Creating New Case or Click Save on any existing case:
You will find Case Description field Contain message that i have passed to custom action through javscript (Highlighted above with Yellow color)




























As a CRM developer, introduction to Custom Actions in this CRM 2013 release is really a great improvement from CRM’s perspective which will help us to minimize the coding part and also achieve some complex requirement easily.

Happy Reading!!!!!

Blogger Widgets