Restrict Lookup Types for Regarding Lookup on Activities


With the following couple of lines of code, we can easily restrict the Lookup Types in Lookup Dialog.

var regarding = Xrm.Page.getAttribute(“regardingobjectid”);
regarding.setLookupTypes([“account”,”contact”]);

RegardingDialog

Advertisements
Posted in CRM, Java Script, Ms Dynamics CRM 2013, MS Dynamics CRM 2015, MS Dynamics CRM 2016 | Tagged , , , , , , , , , , , , , , , | 2 Comments

Command for Generating Optionsets


Command for generating Optionsets:

CrmSvcUtil.exe ^
/codewriterfilter:”Microsoft.Crm.Sdk.Samples.FilteringService, GeneratePicklistEnums” ^
/codecustomization:”Microsoft.Crm.Sdk.Samples.CodeCustomizationService, GeneratePicklistEnums” ^
/namingservice:”Microsoft.Crm.Sdk.Samples.NamingService, GeneratePicklistEnums” ^
/url:http://<domain name>/XRMServices/2011/Organization.svc ^
/username:<user name> ^
/password:<Password>^
/out:OptionSets.cs

Posted in CRM, Ms Dynamics CRM 2013, MS Dynamics CRM 2015, MS Dynamics CRM 2016 | Leave a comment

Calling the Web Service through Java Script



Download the Soap client script from Codeplex:
http://javascriptsoapclient.codeplex.com/

Then Add the Soap client script file on Form consume the functions to call the external public hosted web service.
Sample code to call the web service using the Soap client.
function EntityOnChange()
{
var entity = null;

if (!IsNull(Xrm.Page.getAttribute("new_entity"))) {
if (!IsNull(Xrm.Page.getAttribute("new_entity").getSelectedOption()))
entity = Xrm.Page.getAttribute("new_entity").getSelectedOption().text;
}
var params = new SOAPClientParameters();
//Gets recently Viewed Data
//SOAPClient.invoke("https:///AppWebServices/RecentlyViewedWebService.asmx", "RetrieveRecentlyViewedData", params, true, HelloTo_callBack);

params.add("entityName", entity);

SOAPClient.invoke("https:///AppWebServices/LookupService.asmx", "RetrieveTypeCode", params, true, HelloTo_callBack);
}

function HelloTo_callBack(r) {
alert(r);
}

Posted in Ms Dynamics CRM 2013 | Leave a comment

Re-Activate Case Plugin


If Case is getting Re-Activated and need to perform some logic. Following is the Code snippet.

It should be registered on both messages i.e. SetState and SetStateDynamicEntity.

IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

if (context.InputParameters.Contains(“EntityMoniker”) && context.InputParameters[“EntityMoniker”] is EntityReference)
{
EntityReference entity = (EntityReference)context.InputParameters[“EntityMoniker”];
if (entity.LogicalName != “incident”)
return;
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

//If the Case is getting Re-Activated
if (context.InputParameters.Contains(“State”) && (context.InputParameters[“State”] as OptionSetValue).Value == 0)
{
//Develop Your Logic Here
}
}

Posted in CRM, Java Script, Ms Dynamics CRM 2013, MS Dynamics CRM 2015 | Leave a comment

Resolve Case without Case Resolution Dialog


Resolve Case without case Resolution dialog pop-up:

  • Create a Boolean attribute, place it on form and set visible false.
  • Create a Ribbon Command on Case using Ribbon Workbench.
  • case1
  • Create a client side script (java script) to update the Boolean flag to True. Bind it to the Command button created earlier.
//Called from the Custom Command Button to Resolve the Case without Dialog pop-up
function ResolveCaseCustom() {
try {
Xrm.Page.getAttribute(“new_iscaseresolved”).setValue(true);
Xrm.Page.data.entity.save();
}
catch (error) { Xrm.Utility.alertDialog(error.message, null); }
}
  • Now Create Post Update Plugin with logic to do the Case resolution. Keep in mind that you need to update the Boolean flag to false in plugin because if someone activated the case and click on Resolve it won’t function as desired. Hence we need to update the Boolean field to False.
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Samples
{
public class PostUpdateCase : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity)
{
Entity entity = (Entity)context.InputParameters[“Target”];

if (entity.LogicalName != “incident”)
return;

try
{
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

//If Case Resolved flag check
if (entity.Attributes.Contains(“new_iscaseresolved”) && entity.Attributes[“new_iscaseresolved”] != null && Convert.ToBoolean(entity.Attributes[“new_iscaseresolved”]))
{
//Update the Is Resolve Flag to False.
Entity updateCase = new Entity();
updateCase.LogicalName = “incident”;
updateCase.Id = entity.Id;
updateCase.Attributes.Add(“new_iscaseresolved”, false);
service.Update(updateCase);

// Create the incidentresolution.
Entity caseResolution = new Entity(“incidentresolution”);
caseResolution.Attributes.Add(“incidentid”, new EntityReference(“incident”, entity.Id));
caseResolution.Attributes.Add(“subject”, “Closed”);
// Close the incident with the resolution.
CloseIncidentRequest req = new CloseIncidentRequest();
req.IncidentResolution = caseResolution;
req.RequestName = “CloseIncident”;
OptionSetValue o = new OptionSetValue();
o.Value = 5;
req.Status = o;
CloseIncidentResponse resp = (CloseIncidentResponse)service.Execute(req);
}
}
catch (InvalidPluginExecutionException)
{
throw;
}
}
}
}
}

 

  • While registering the Plugin make sure the Plugin would get fired only when the Flag is updated.
 case2

 

  • That’s it. Done.

 

Posted in CRM, Java Script, Ms Dynamics CRM 2013, MS Dynamics CRM 2015 | Leave a comment

Save, Resolve the Case and Refresh the Form



//Save the Form
Xrm.Page.data.entity.save();

//Build Request - Here the Status would be "Resolved" and Status Reason is 5 i.e. Problem Solved Pass Entity ID
var request = "<s:Envelope xmlns:s='http://schemas.xmlsoap.org/soap/envelope/'>" +
" <s:Body>" +
" <Execute xmlns='http://schemas.microsoft.com/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>" +
" <request i:type='b:CloseIncidentRequest' xmlns:a='http://schemas.microsoft.com/xrm/2011/Contracts' xmlns:b='http://schemas.microsoft.com/crm/2011/Contracts'>" +
" <a:Parameters xmlns:c='http://schemas.datacontract.org/2004/07/System.Collections.Generic'>" +
" <a:KeyValuePairOfstringanyType>" +
" <c:key>IncidentResolution</c:key>" +
" <c:value i:type='a:Entity'>" +
" <a:Attributes>" +
" <a:KeyValuePairOfstringanyType>" +
" <c:key>incidentid</c:key>" +
" <c:value i:type='a:EntityReference'>" +
" <a:Id>" + entityid + "</a:Id>" +
" <a:LogicalName>incident</a:LogicalName>" +
" <a:Name i:nil='true' />" +
" </c:value>" +
" </a:KeyValuePairOfstringanyType>" +
" </a:Attributes>" +
" <a:EntityState i:nil='true' />" +
" <a:FormattedValues />" +
" <a:Id>00000000-0000-0000-0000-000000000000</a:Id>" +
" <a:LogicalName>incidentresolution</a:LogicalName>" +
" <a:RelatedEntities />" +
" </c:value>" +
" </a:KeyValuePairOfstringanyType>" +
" <a:KeyValuePairOfstringanyType>" +
" <c:key>Status</c:key>" +
" <c:value i:type='a:OptionSetValue'>" +
" <a:Value>" + 5 + "</a:Value>" +
" </c:value>" +
" </a:KeyValuePairOfstringanyType>" +
" </a:Parameters>" +
" <a:RequestId i:nil='true' />" +
" <a:RequestName>CloseIncident</a:RequestName>" +
" </request>" +
" </Execute>" +
" </s:Body>" +
"</s:Envelope>";
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("POST", Xrm.Page.context.prependOrgName("/XRMServices/2011/Organization.svc/web"), false)
xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
xmlHttpRequest.send(request);

//Refresh the Data
Xrm.Page.data.refresh();

Posted in CRM, Java Script, Ms Dynamics CRM 2013, MS Dynamics CRM 2015 | 1 Comment

Changing Dashboard Default Setting


1. Open a Powershell window on your CRM server – ‘Start > Run > “PowerShell” > OK‘.
2. Add the Microsoft Dynamics CRM PowerShell snap-in – ‘Add-PSSnapin Microsoft.Crm.PowerShell‘.
3. Enter the following command to retrieve the current setting – ‘$setting = Get-CrmSetting -SettingType DashboardSettings‘.
4. Modify the setting (in this case we’ll increase the number of items allowed to 9) – ‘$setting.MaximumControlsLimit = 9‘.
5. And finally save the setting – ‘Set-CrmSetting -Setting $setting‘.

Powershell[1]

Posted in Ms Dynamics CRM 2013, MS Dynamics CRM 2015 | Leave a comment