Try out – Ribbon Workbench for Dynamics CRM 2011


Hi,

Today i came across this new tool for Ribbon editing in CRM 2011.

http://www.develop1.net/public/page/Ribbon-Workbench-for-Dynamics-CRM-2011.aspx

The tools looks really wonderful.

Will try it out soon.

Bye.

 

 

Getting the IncidentId on resolving a Case in post Close plugin.


Hi,

To get the id of the case record which is getting resolved in the plugin, we need to make use of IncidentResolution inputparameters of the context.


Entity incRes = this.Context.InputParameters["IncidentResolution"] as Entity;
 Guid caseId = ((EntityReference)incRes.Attributes["incidentid"]).Id;

Bye.

Use “Close” message when we “Resolve” an Incident (Case) in CRM.


We had one plugin which was registered against “SetState” and “SetStateDynamic” message. It used to run when we were doing “Cancel Case” from the ribbon.

We thought the same message will work in case of “Resolve Case“.

However in case of Resolve Case, we need to use or register our plugin against the “Close” message.

InputParametersà

Hope it helps.

Showing related entity information in Header as Hyperlink – CRM 2011


We recently had requirement to show the Case Information in one of its related (related) entity’s header. The information should appear as a hyperlink so that users can open the case directly from that entity’s form.

Case entity was having 1-n relationship with this other entity say Entity A and Entity A was related 1-n with Entity B. In Entity A we had moved the lookup of Case in the header. So from Entity A’s form user could click the lookup in header (as lookup appeared as hyperlink in Header) and open the Case.

Now they wanted the similar kind of functionality in Entity B. However as Entity B was not directly related to Case entity it had no lookup or any other field having Case information in it.

So this is what we did :-

  1. Created a new HTML Web Resource.
  2. Added an anchor tag in it.
  3. Used JavaScript to get the Case Information from the lookup of the Entity A in the form.
  4. Dynamically setting the href and innerHTML of the anchor tag so that it provides case information and link clicking on which should open the case record.
  5. Add the Web Resource in the header of the Entity B form.
  6. As we were using JSON here, added the JSON library in the form load.

    Case Information in the header and the hyperlink:-

Sample Code of the HTML Web Resource:-


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Case Information</title>
 <script src="ClientGlobalContext.js.aspx"></script>
 <script type="text/javascript" src="new_json2"></script>
 <style type="text/css">
 .ms-crm-Field-Normal
 {
 font-family: Segoe UI, Tahoma, Arial;
 font-size: 13px;
 position:absolute;
 top:0px;
 text-align: left;
 }


 </style>
 <meta charset="utf-8">
</head>
<body style="background-color: #f7fbff; margin: 10px" onload="GetCaseInformation()"
 contenteditable="true">
 <a id="anchorCase" href="#" target="_blank" class="ms-crm-Field-Normal"></a>
 <script>

var FORM_TYPE_UPDATE = 2;
 var FORM_TYPE_READ_ONLY = 3;
 var FORM_TYPE_DISABLED = 4;


 var ODataPath;
 var serverUrl;
 var entityName = "";
 var id = "";
 var entity;

function GetCaseInformation() {
 init();
 }

function init() {


 serverUrl = document.location.protocol + "//" + document.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
 ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
 if (parent.Xrm.Page.ui.getFormType() == FORM_TYPE_UPDATE ||
 parent.Xrm.Page.ui.getFormType() == FORM_TYPE_READ_ONLY ||
 parent.Xrm.Page.ui.getFormType() == FORM_TYPE_DISABLED) {

// get the lookup control and its guid and entity type
 var value = parent.Xrm.Page.ui.controls.get('new_casemedicalconditionid').getAttribute().getValue();

if (value != null) {
 id = value[0].id.replace('{', '').replace('}', '');
 entityName = value[0].entityType;
 }
 }
 // get the case information
 retrieveRecord(id);
 }

function retrieveRecord(Id) {
 var retrieveReq = new XMLHttpRequest();
 var url = ODataPath + "/" + entityName + "Set(guid'" + Id + "')";

retrieveReq.open("GET", ODataPath + "/" + entityName + "Set(guid'" + Id + "')", true);
 retrieveReq.setRequestHeader("Accept", "application/json");
 retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
 retrieveReq.onreadystatechange = function () {
 retrieveReqCallBack(this);
 };
 retrieveReq.send();
 }

function retrieveReqCallBack(retrieveReq) {


 if (retrieveReq.readyState == 4 /* complete */) {
 if (retrieveReq.status == 200) {
 //Success

 entity = JSON.parse(retrieveReq.responseText).d;
 if (entity.new_CaseId != null) {
 var caseGuid = entity.new_CaseId.Id;
 var caseName = entity.new_CaseId.Name;
 var serverUrl = document.location.protocol + "//" + document.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
 if (document.getElementById('anchorCase').innerHTML == "") {
 document.getElementById('anchorCase').innerHTML = caseName;
 document.getElementById('anchorCase').href = serverUrl + "/CS/cases/edit.aspx?id={" + caseGuid + "}";
 }
 }
 }
 }
 }

</script>
</body>
</html>


Bye.

Used Multiple Forms in CRM 2011


As we all know that we have new multiple forms feature in CRM 2011, which allows us to create multiple forms for an entity. Today for the first time I got an opportunity to implement it.

Our scenario was something like this :-

We wanted only specific users to Reactivate Case and they shouldn’t be able to modify any value on the case that they are Reactivating.

We started by first figuring out the minimum rights required to Reactivate the case and they were

  1. Create
  2. Write
  3. Append To

for the Case entity.

Obviously with Write access user will be able to modify the values for the case.

So we did the following

  1. Created a new custom security role having the above mentioned privileges.
  2. Created a new form for the Case Entity.
  3. Removed few of the sections/fields and set the remaining fields as Read Only (through form customization and not JavaScript) for the new form.
  4. Used Assign Security Roles to and selected the newly created security roles as Display only to these selected security roles option


  5. For the main Information form, we selected the same option Display only to these selected security roles and this time checked all other roles and unchecked the new security roles created.

So now when the user having the new security role opens the case form for Reactivating the Case, he only sees the newly created form which has all the fields set as read only.

This solved our purpose.

Hope it helps.

Reactivate Case in CRM 2011


Hi,

Below the minimum rights required to Reactivate a closed or resolved Case in CRM.

Sample code to do it through code


private void Form_Load(object sender, EventArgs e)
 {
 Uri organizationUri = new Uri("http://servername/orgname/XRMServices/2011/Organization.svc");
 Uri homeRealmUri = null;
 ClientCredentials credentials = new ClientCredentials();
 credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
 OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
 IOrganizationService _service = (IOrganizationService)orgProxy;
 ReactivateState("incident", new Guid("caseGuid"), 0, -1, _service);
 }

public static void ReactivateState(string entityName, Guid entityGuid, int state, int status, IOrganizationService orgService)
 {
 try
 {
 SetStateRequest req = new SetStateRequest();
 req.EntityMoniker = new EntityReference(entityName, entityGuid);
 req.State = new OptionSetValue(state);
 req.Status = new OptionSetValue(status);
 orgService.Execute(req);
 }
 catch (Exception ex)
 {

 }
 }

Bye.