Posts

Showing posts from December, 2016

Associate Lead to Email Send in Dynamics CRM

The Associate Lead to Email Send custom workflow activity will accept a Lead and an Email Send and associate the two via a CRM many-to-many relationship named cdi_emailsend_lead Inputs Name Type Notes Email Send EntityReference (cdi_emailsend) Lookup to the Email Send Lead EntityReference (lead) Lookup to the Lead Name Type Notes Success Boolean Indicates Success or failure of the code Outputs Associate two records using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Messages; using Microsoft.Xrm.Sdk.Workflow; using System; using System.Activities; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CustomWorkflow {     public class AssociateContactToEmailSend : CodeActivity     {         #region Input Properties         [RequiredArgument]         [Input("Contact")]

Update the fetchXML that will be used by the Sub- grid in Dynamics CRM

///<reference path="XrmPage-vsdoc.js"/> function UpdateSubGrid() {  window.scroll(0,0);  var rereferralsGrid = document.getElementById("rereferrals");  var lookupfield = new Array;  lookupfield = Xrm.Page.getAttribute("ftd_familymember").getValue();  intakeid = Xrm.Page.getAttribute("safy_intakeid").getValue();  if (lookupfield != null)  {      var lookupid = lookupfield[0].id;  } else  {     return;  } if (rereferralsGrid ==null || rereferralsGrid.readyState != "complete") {     setTimeout('UpdateSubGrid()', 2000);     return; }     //Update the fetchXML that will be used by the grid.  var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"   fetchXml += "<entity name='ftd_intakeassessment'>";  fetchXml += "<attribute name='safy_intakeassessment'/>";

Formats a postal code & Sets a lookup field in Javascript

function formatPostalcode(pcode) {     var regexObj = /^\s*([a-ceghj-npr-tvxy]\d[a-ceghj-npr-tv-z])(\s)?(\d[a-ceghj-npr-tv-z]\d)\s*$/i     if (regexObj.test(pcode)) {         var parts = pcode.match(regexObj);         var pc = parts[1] + " " + parts[3];         return pc.toUpperCase();     }     else {         return pcode;     } } function SetLookup(fieldName, idValue, textValue, typeValue) {     var value = new Array();     value[0] = new Object();     value[0].id = idValue;     value[0].name = textValue;     value[0].typename = typeValue;     setDisabledField(fieldName, value); }

Gets the current user and enters string into specified field

function loggedUser(field) {     var user = Xrm.Page.context.getUserId();     var userId = user.substring(1, 37);     var serverUrl = document.location.protocol;     serverUrl += "//" + document.location.host;     serverUrl += "/" + Xrm.Page.context.getOrgUniqueName();     var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";     var ODATA_EntityCollection = "/SystemUserSet";     var ODATA_Query = "(guid\'" + userId + "')";     var ODATA_Final_url = serverUrl + ODATA_ENDPOINT + ODATA_EntityCollection + ODATA_Query;     $.ajax({         type: "GET",         contentType: "application/json; charset=utf-8",         datatype: "json",         url: ODATA_Final_url,         beforeSend: function (XMLHttpRequest) {             XMLHttpRequest.setRequestHeader("Accept", "application/json");         },         success: function (data, textStatus, XmlHttp

Checks to see if the user has a particular role in Dynamics CRM

//  UserHasRole(roleName)           Checks to see if the user has a particular role function UserHasRole(roleName) {     var oXml = GetCurrentUserRoles();     if (oXml != null)     {         var roles = oXml.selectNodes("//BusinessEntity/q1:name");         if (roles != null)         {             for (i = 0; i < roles.length; i++)             {                 if (roles[i].text == roleName)                 {                     return true;                 }             }         }     }     return false; } //  GetCurrentUserRoles()           Gets user's security roles function GetCurrentUserRoles() {     var xml = "" +      "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +      "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +

Show Hide Sections in MS Dynamics CRM

/************************************************ stateSectionsOnChange - function to handle which fields  to show based on the state selected ************************************************/ function stateSectionsOnChange() {     var closeTab = Xrm.Page.ui.tabs.get("Professional Info"); var showTXSection = false;     var showOHSection = false;     var showINSection = false;     switch (Xrm.Page.getAttribute("col_addressstate").getText()) {         case "Texas": showTXSection = true;             showOHSection = false; showINSection = false;             break;         case "Ohio": showTXSection = false;             showOHSection = true; showINSection = false;             break;         case "Indiana": showTXSection = false;             showOHSection = false; showINSection = true;             break;     }     closeTab.sections.get("Texas").setVisible(showTXSection);     closeTab.