Model Driven Apps were released as a part of 8.2 release (and were called just Apps that time). It’s really cool feature that allows you to build role-tailored applications that have functionality required for specific role. What is available through UI unfortunately is not available through workflows – there is no possibility to define specific …
Category: Howto
HowTo: open plugin/custom workflow activity project created using CRM/D365 Developer Toolkit
I have to confess that I used to use CRM Developer Toolkit (CRMDT) before Jason Lattimer’s VS extensions were released. After I uninstalled CRMDT I started to experience issues opening projects created using it. Following error message appeared when I tried to open a solution: Here is how it can be easily fixed:
Enable plus button for subgrids on disabled forms
Several weeks ago I got a question from my customer – when record is inactive it’s not possible to add associated records from subgrids located on entity form – is it possible to bring back “plus” button to the subgrid even if record is deactivated?
Pass DateTime parameters to set field record values
Today I got requirement to open new record form with prepopulated DateTime field. This article describes how to pre-set Date field: The following sample sets the Est. Close Date field for a new opportunity to January 31, 2011. The unencoded value for the extraqs parameter is “estimatedclosedate=01/31/11”. No single word about time component. Luckily I …
How to share record with user using WebApi
You can use following code to share record (account in this case) with user (but you can share it with team as well) using JavaScript and WebApi without any additional development:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
var target = { "accountid": "ACAAB842-21C7-E811-A96F-000D3A16A41E", //put <other record type>id and Guid of record to share here "@odata.type": "Microsoft.Dynamics.CRM.account" //replace account with other record type }; var principalAccess = { "Principal": { "systemuserid": "d272654b-57f5-4564-8d0b-36d0d4c426c4", //put teamid here and Guid of team if you want to share with team "@odata.type": "Microsoft.Dynamics.CRM.systemuser" //put team instead of systemuser if you want to share with team }, "AccessMask": "ReadAccess, WriteAccess" //full list of privileges is "ReadAccess, WriteAccess, AppendAccess, AppendToAccess, CreateAccess, DeleteAccess, ShareAccess, AssignAccess" }; var parameters = { "Target": target, "PrincipalAccess": principalAccess }; var context; if (typeof GetGlobalContext === "function") { context = GetGlobalContext(); } else { context = Xrm.Page.context; } var req = new XMLHttpRequest(); req.open("POST", context.getClientUrl() + "/api/data/v9.0/GrantAccess", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 204) { //Success - No Return Data - Do Something } else { var errorText = this.responseText; //Error and errorText variable contains an error - do something with it } } }; req.send(JSON.stringify(parameters)); |
How to call QuerySchedule using WebApi
Following code can be used to call QuerySchedule function using WebApi:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
var context; if (typeof GetGlobalContext === "function") { context = GetGlobalContext(); } else { context = Xrm.Page.context; } var start = new Date(); //Put Start datetime here var end = new Date(); //Put End datetime here end.setDate(end.getDate() + 1); var requestUrl = "/api/data/v8.2/QuerySchedule(ResourceId=@p1,Start=@p2,End=@p3,TimeCodes=@p4)"; requestUrl += "?@p1=" + context.getUserId().replace("{", "").replace("}", ""); //put Id of resource you want get data for as parameter 1 requestUrl += "&@p2=" + JSON.stringify(start).replace(/"/g, ""); requestUrl += "&@p3=" + JSON.stringify(end).replace(/"/g, ""); requestUrl += "&@p4=" + JSON.stringify(['0']); //For TimeCodes use '0' for Available //'1' for Busy //'2' for Unavailable //'3' for Filter var req = new XMLHttpRequest(); req.open("GET", context.getClientUrl() + requestUrl, true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var results = JSON.parse(this.response); //you've got results to results variable } else { var errorText = this.responseText; //handle error here } } }; req.send(); |
How to Add Item to Campaign using WebApi
Following JS (with small changes) can be used to add Marketing List/Product/Sales Literature to Campaign:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
var parameters = { Campaign: { campaignid: "E5EE91B6-7A75-E811-A95F-000D3A33EB4E", //put valid if of campaign here "@odata.type": "Microsoft.Dynamics.CRM.campaign" } }; var context; if (typeof GetGlobalContext === "function") { context = GetGlobalContext(); } else { context = Xrm.Page.context; } var req = new XMLHttpRequest(); req.open("POST", context.getClientUrl() + "/api/data/v8.2/lists(2DBBE7F5-7A75-E811-A95F-000D3A33EB4E)/Microsoft.Dynamics.CRM.AddItemCampaign", true); //replace collection name and record id with record you want to add to campaign req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 204) { //Success - No Return Data - Do Something } else { var errorText = this.responseText; //Error and errorText variable contains an error - do something with it } } }; req.send(JSON.stringify(parameters)); |
How to generate Excel Template from code
2 years ago as a part of Dynamics CRM 2016 release Microsoft introduced “Word/Excel Document Templates”. I saw examples how to generate Word template but have never seen the same example for Excel. Here is what I found after several hours spent with DB of CRM and ILSpy:
|
1 2 3 4 5 6 7 8 9 10 |
var request = new OrganizationRequest("RenderTemplateFromView"); request["Template"] = new EntityReference("documenttemplate", new Guid("ECF388DE-1033-4C7C-93F3-0803B16C09C7")); request["View"] = new EntityReference("savedquery", new Guid("00000000-0000-0000-00AA-000010003001")); var response = service.Execute(request); var fileContent = (byte[]) response["ExcelFile"]; //Do whatever you need with file content - I saved it to hard drive File.WriteAllBytes("GeneratedExcel.xlsx", fileContent); |
Huge limitation of this code – …
How to use SendEmailFromTemplate action with JavaScript and WebApi
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
var parameters = { TemplateId: "07B94C1D-C85F-492F-B120-F0A743C540E6",//Guid of template Regarding: { contactid: "CA26BD09-62B4-E711-A94F-000D3A109280",//entity that will be used for templating "@odata.type": "Microsoft.Dynamics.CRM.contact" }, Target: {//stub of email that has to contain at least one valid recipient "@odata.type": "Microsoft.Dynamics.CRM.email", email_activity_parties: [{ "partyid_contact@odata.bind": "/contacts(CA26BD09-62B4-E711-A94F-000D3A109280)", participationtypemask: 2//To }] } }; var context; if (typeof GetGlobalContext === "function") { context = GetGlobalContext(); } else { context = Xrm.Page.context; } var req = new XMLHttpRequest(); req.open("POST", context.getClientUrl() + "/api/data/v8.2/SendEmailFromTemplate", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { //Success - No Return Data - Do Something } else { var errorText = this.responseText; //Error and errorText variable contains an error - do something with it } } }; req.send(JSON.stringify(parameters)); |
How to Add records to Marketing List using WebApi
Following code can be used to add records to Marketing List using JavaScript and WebApi:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
var parameters = { List: { listid: "9DEE7D76-611D-E811-A95B-000D3A1087A0", "@odata.type": "Microsoft.Dynamics.CRM.list" }, Members: [{ accountid: "3653A521-A2C0-E711-A950-000D3A109280", "@odata.type": "Microsoft.Dynamics.CRM.account" }] }; var context; if (typeof GetGlobalContext === "function") { context = GetGlobalContext(); } else { context = Xrm.Page.context; } var req = new XMLHttpRequest(); req.open("POST", context.getClientUrl() + "/api/data/v8.2/AddListMembersList", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 204) { //Success - No Return Data - Do Something } else { var errorText = this.responseText; //Error and errorText variable contains an error - do something with it } } }; req.send(JSON.stringify(parameters)); |