Wednesday, May 20, 2020

Custom buttons are not appearing in UCI

Microsoft have updated the Unified Interface’s UI with big improvements to the Sitemap and Command bar.
I have been facing this issue in unified interface, I did a lot of research on this and followed the below steps to resolve

We first need to get the organization id, this can be found in Settings > Customization's -> Developer Resources

or type the below command in Console
//Xrm.Utility.getGlobalContext().organizationSettings;
Xrm.Utility.getGlobalContext().organizationSettings.organizationId;

Open CRM Instance -- > Press F12 --> Console (execute the below scripts)

Xrm.WebApi.online.updateRecord("organization","{ORGANIZATIONID}", {"clientfeatureset":'<clientfeatures><clientfeature xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-Instance\"><name>FCB.ShellRefresh</name><value>true</value><location>Organization</location></clientfeature></clientfeatures>'})

Xrm.WebApi.online.updateRecord("organization", "{ORGANIZATIONID}", 
{'clientfeatureset':'<clientfeatures><clientfeature xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-Instance\"><name>FCB.DashboardCustomizableRibbon</name><value>true</value></clientfeature></clientfeatures>'})

Before executing Script


After executing the above script in Console window, we can see the button

E = "FCB.Client.Chart.DrillDown"
W = "FCB.DashboardCustomizableRibbon"
P = "FCB.DisableEditableGridControlOnPhone"
T = "FCB.LookupService"
N = "FCB.LookupQuickFind"

That’s it , your custom buttons will be available now in UCI.

Set Default View in CRM Subgrid


function subGridLookupView(){

debugger;
var subgrid= Xrm.Page.getControl("lookup_grdContacts");
if (subgrid!= null){
// you can add other conditions(subgrid!= 'undefined' || subgrid!='') as per your criteria 
//get the view ID from Advanced find Look for : View  and add the condition Name Equals "CustomContactsView"
Xrm.Page.getControl("lookup_ grdContacts ").setDefaultView("{00000000-0000-0000-0000-000000000000}");
                }
setTimeout(subGridLookupView, 1000);
}

Tuesday, May 19, 2020

Calling Workflow using JavaScript


var clientUrl = Xrm.Page.context.getClientUrl();
var workflowId = "workflow guid";
var entityId = "entityID";

var requestUri = clientUrl + "/api/data/v9.0/workflows(" + workflowId + ")/Microsoft.Dynamics.CRM.ExecuteWorkflow";

var xhr = new XMLHttpRequest();
xhr.open("POST", requestUri, true);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");
xhr.setRequestHeader("OData-MaxVersion", "4.0");
xhr.setRequestHeader("OData-Version", "4.0");
xhr.onreadystatechange = function () {
    if (this.readyState == 4) {
        xhr.onreadystatechange = null;
        if (this.status == 200) {
            var result = JSON.parse(this.response);
        } else {
            var error = JSON.parse(this.response).error;
        }
    }
};
xhr.send("{\"EntityId\":\"" + entityId + "\"}");


to get Workflow ID using Name
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="workflow">
    <filter type="and">
      <condition attribute="name" operator="eq" value="Enter Workflow Name Here!" />
    </filter>
  </entity>
</fetch>


Servicepointmanager does not support proxies with the https scheme


I started getting this in VS2015 on one of my machines. I had an additional package feed on myget which constantly asked me for credentials and failed even when entering correct credentials. 
What helped me was clearing the nuget cache and config by deleting these two nuget folders:
  1.          %APPDATA%\NuGet
  2.          %LOCALAPPDATA%\NuGet


After that I restarted Visual Studio and added my custom package source again.

Refresh CRM Page

Hard refresh CRM Page using the below scripts

window.location.reload(true);
//location.reload();

Wednesday, August 14, 2019

Set Default view in inline Lookup D365


function loadCustomDefaultView(){
debugger;
var subgrid= Xrm.Page.getControl("subgridname");
    if (subgrid != null || subgrid != 'undefined' || subgrid !='')) {
Xrm.Page.getControl("subgridname").setDefaultView("GUID");
   }
}

Update the content of Activated Quote in CRM


We got a situation as, the quote should activated for triggering a workflow and from workflow on based on some conditions we need to update the same quote. This is not possible as the quote becomes Read-Only immediately after you activate. 
 
If we want to update it, the option is revising the quote which closes the current quote and creates a new quote where we don't want to create new quotes.
 
After some search, we found a way for doing it and the way is very simple. Just change the state of quote to Draft, update the data and then change the quote state to Active which will not create any new quote.
 
We can do this using a system workflow and also from SDK.
 
System Workflow
 
SDK
// Change the Quote to Draft State
SetStateRequest draftQuote = new SetStateRequest();
draftQuote.EntityMoniker = new EntityReference("quote"newGuid(""));
draftQuote.State = new OptionSetValue(0); // Draft
draftQuote.Status = new OptionSetValue(1); // InProgress
objService.Execute(draftQuote);

// Update the Quote
Entity entQuote = new Entity("quote");
entQuote.Attributes["name"] = "testing1";
entQuote.Id = new Guid("DA5768B5-D62A-E511-80E0-FC15B4283778");
objService.Update(entQuote);

// Change the Quote to Active State.
SetStateRequest activateQuote = new SetStateRequest();
activateQuote.EntityMoniker = new EntityReference("quote"newGuid(""));
activateQuote.State = new OptionSetValue(1); // Active
activateQuote.Status = new OptionSetValue(2); // InProgress
objService.Execute(activateQuote);

Hope this helps.