How To : Retrieve the Marketing Lists Count Associated With An Event in CRM Using JavaScript

Hi, in this article am gonna show how to retrieve marketing lists count associated with certain event in CRM Using JavaScript.

Code:

function retrieveEventAssociatedLists(EventID) {

var listsCount = 0;

var serverUrl = "http://" + document.location.href.split("/")[2];

var ODataPath = serverUrl + "/OrganizationName/XRMServices/2011/OrganizationData.svc";

var retrieveEventListsReq = new XMLHttpRequest();

retrieveEventListsReq.open("GET", ODataPath + "/new_new_event_listSet?$filter=new_eventid eq guid'" + EventID + "'",   false);

retrieveEventListsReq.setRequestHeader("Accept", "application/json");

retrieveEventListsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");

retrieveEventListsReq.send();

if (retrieveEventListsReq.status == 200) {

//Success

var retrievedEventLists = JSON.parse(retrieveEventListsReq.responseText).d;

listsCount = retrievedEventLists.results.length;

}

return listsCount;

}

Dynamcis 365 - Override Lookup view using Java script

Hi,

I have encountered some scenarios  in which I needed to override lookup view columns or apply some filters on the results depending on dynamics conditions at run time on CRM form.

In order to do that , add the following piece of code in the on load event

The following example filters results set no a specific case type

 

var viewId = "{00000000-0000-0000-0000-000000000001}";

//add the entity name
var entityName = "incident";

// add the view display name
var viewDisplayName = "Problem Cases";

var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='incident'>" +
" <attribute name='title' />" +
"<attribute name='customerid' />" +
"<attribute name='incidentid' />" +
"<order attribute='title' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='bps_type' operator='eq' value='200000005' />" +
" </filter>" +
" </entity>" +
"</fetch>";

var layoutXml = "<grid name='resultset' object='1' jump='productid' select='1' icon='1' preview='1'>" +
"<row name='result' id='incidentid'>" +
"<cell name='title' width='150' />" +
"<cell name='customerid' width='150' />" +
"</row>" +
"</grid>";

Xrm.Page.getControl("parentcaseid").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);

Quick View Form and sub grid Issue in Dynamics 365

Hi,

Intro :

I encountered a problem while working with quick view forms having sub grids.

The quick view form is meant to display the account details upon selecting an account on lookup in custom entity form.

Problem:

Quick view form has sub grid displaying related record to account such as cases and opportunities , the problem occurs whenever you change the select account , all the details are updated to reflect the new selected account except the sub grids .

 They keep displaying the related records to the old one.

Fix :

  1. Add on change event handler on the account lookup
  2. Include the following piece of code in your java script function

var quickViewControl = Xrm.Page.ui.quickForms.get("your quick view form name");
if (quickViewControl != undefined) {
if (quickViewControl.isLoaded()) {
quickViewControl.refresh();
}
}

How To : Set A Fields On A Form Required Or Recommended Using Java Script in CRM

// Required

Xrm.Page.getAttribute("FieldSchemaName").setRequiredLevel("required");

//Recommended

Xrm.Page.getAttribute("FieldSchemaName").setRequiredLevel("recommended");

// None

Xrm.Page.getAttribute("FieldSchemaName").setRequiredLevel("none");

MS CRM - What is the "IsDirty" Method ?

Hi,

The "IsDirty()" Method returns a Boolean value indicating if there are unsaved changes to  attributes values.

Code:

//To Check if the entity is dirty
var ismodified=Xrm.Page.data.entity.getIsDirty();

//To Get Dirty Fields
var attributes = Xrm.Page.data.entity.attributes.get() ;
for (var i in attributes)
{
var attribute = attributes[i];
if (attribute.getIsDirty())
alert("attribute dirty: " + attribute.getName());
}