d365 v9 Archives -

Tag Archives: d365 v9

Filter Customer Type field to display only Accounts in D365 V9.0 using JavaScript

Posted On December 25, 2018 by Clinton D'Mello Posted in Tagged in

Introduction: In this blog we will see how to filter customer type field in Dynamics 365 to only show Accounts/Contacts dropdown. Implementation: Step 1: For demonstration purpose we will filter to only show Accounts. In the below image we can see that we have  a Customer type field which allows to choose from Contacts as well as Accounts. Note: Here accounts are called as Companies. Step 2: To display only Companies in the dropdown we register an event on Form Load. Here we are working on the Contacts form, hence we first write a JavaScript code to filter the lookup to show only companies. Below shown in the code: Code: var oContactFormCustomization = { setCustomerLookupToShowCompany: function (execContext) { var formContext = execContext.getFormContext(); if (formContext.getControl(“parentcustomerid”)) { var company = formContext.getControl(‘parentcustomerid’); if (company.getEntityTypes().length > 1) { company.setEntityTypes([‘account’]); } } }}; We add this script in CRM JS Web resource and add the library on the Contact form Properties Below shown is the Handler Properties Once this is done we can see when the form loads the scripts executes and we can now view only the Companies and not the Contacts Hope this helped!

[SOLVED] “Corrupted report PDF generated using JavaScript” in Dynamics 365 V9.0

Posted On October 9, 2018 by Clinton D'Mello Posted in Tagged in

Introduction We had developed a functionality for Dynamics CRM v8.2 on Quote Entity by adding a custom button and on clicking a button we run a report, capture its contents using JavaScript, convert it to a PDF and attach the PDF to an Email Record. Below shown is the code snippet quoteInvoice = { runReportToPrint: function () { debugger; var params = quoteInvoice.getReportingSession(); var newPth = Xrm.Page.context.getClientUrl() + “/Reserved.ReportViewerWebControl.axd?ReportSession=” + params[0] + “&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=” + params[1] + “&OpType=Export&FileName=public&ContentDisposition=OnlyHtmlInline&Format=PDF”; //Calling the below function converts the report to PDF format. quoteInvoice.convertResponseToPDF(newPth); }, getReportingSession: function () { var selectedIds = Xrm.Page.data.entity.getId(); selectedIds = selectedIds.replace(‘{‘, ”).replace(‘}’, ”); var strParameterXML = “<fetch distinct=’false’ mapping=’logical’ output-format=’xml-platform’ version=’1.0′><entity name= ‘quote’><all-attributes/><filter type=’and’><condition attribute=’quoteid’ value='” + selectedIds + “‘ operator=’eq’ /></filter></entity ></fetch >”; var reportGuid = “DAF05843-CA33-E711-811E-FC15B42827EC”; var reportName = “Quote Invoice.rdl”; var pth = Xrm.Page.context.getClientUrl() + “/CRMReports/rsviewer/QuirksReportViewer.aspx”; var retrieveEntityReq = new XMLHttpRequest(); retrieveEntityReq.open(“POST”, pth, false); retrieveEntityReq.setRequestHeader(“Accept”, “*/*”); retrieveEntityReq.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded”); retrieveEntityReq.send(“id=%7B” + reportGuid + “%7D&uniquename=” + Xrm.Page.context.getOrgUniqueName() + “&iscustomreport=true&reportnameonsrs=&reportName=” + reportName + “&isScheduledReport=false&p:quoteid=” + strParameterXML); var x = retrieveEntityReq.responseText.lastIndexOf(“ReportSession=”); var y = retrieveEntityReq.responseText.lastIndexOf(“ControlID=”); var ret = new Array(); ret[0] = retrieveEntityReq.responseText.substr(x + 14, 24); ret[1] = retrieveEntityReq.responseText.substr(x + 10, 32); return ret; } } The runReportToPrint() function is called when the custom button is clicked Issue and Error Details Once the environment was upgraded to V9.0 we were facing issues as the PDF that was generated was corrupted as show below. While debugging the code we got the following message. On further research we found that the URL has been changed and  below shown is the new path that has to be used which works correctly on V9.0. var pth = Xrm.Page.context.getClientUrl() + “/CRMReports/rsviewer/ReportViewer.aspx”; Once this change was done  we did not get any error and the PDF of the report that was generated opened correctly with all of  its contents.

Get Geolocation details using Xrm.Device for mobile devices

Posted On September 10, 2018 by Clinton D'Mello Posted in Tagged in

Introduction: In this blog we will use the  Xrm.Device Client API reference to get the location details as it provides methods to use native device capabilities of mobile devices. Implementation: Step 1 : First we have written a JavaScript code to get the Geolocation details and for this demonstration purpose we trigger this code to run on update of a field. We have created a custom field as Coordinates to store the details. Syntax: Xrm.Device.getCurrentPosition().then(successCallback, errorCallback) Below shown is the Code: var cordsLat = null; var cordsLong = null; var Scripting = { Location: function () { debugger; Xrm.Device.getCurrentPosition().then( function success(location) { cordsLat = location.coords.latitude; cordsLong = location.coords.longitude; Scripting.UpdateRecord(); }, function (error) { Xrm.Navigation.openAlertDialog({ text: error.message }); } ) }, UpdateRecord: function () { var id = Xrm.Page.data.entity.getId(); id = id.replace(“{“, “”); id = id.replace(“}”,””); var clientUrl = Xrm.Page.context.getClientUrl(); var req = new XMLHttpRequest(); req.open(“PATCH”, encodeURI(clientUrl + “/api/data/v9.0/accounts(” + id + “)”), true); req.setRequestHeader(“Accept”, “application/json”); req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”); req.setRequestHeader(“OData-MaxVersion”, “4.0”); req.setRequestHeader(“OData-Version”, “4.0”); var body = JSON.stringify({ “cf_cordinates”: “Latitude: ” + cordsLat + ” Longitude: ” + cordsLong, }); req.send(body); } } Step 2: One important thing to note is the Xrm.Device control is only available in for mobile devices. When we run this script on a mobile device we get an error message and it does not go after turning on the GPS location of the device. Step 3: To enable the script to work on the device navigate as shown belowOnce this is done and  the script successfully runs we have to refresh the page and the details are updated on the Coordinates field as shown below

Customer Journeys in Dynamics 365 for Marketing

Posted On July 25, 2018 by Clinton D'Mello Posted in Tagged in

Introduction: In this blog we will demonstrate how to create Customer Journeys in Dynamics 365 for Marketing. As you engage potential customers, they start by discovering your product, evaluate whether it meets their needs, look for a good offer, and finally make a purchase. This process is called as Customer journeys. Pre Requisites: Before we start we need to have live segments towards whom we can target our marketing initiatives. Check out how to create segments here. We also need to have our Marketing emails designed and ready to go. Check out how to create marketing emails here. Implementation: In our scenario we have taken an example where CloudFronts wants to organize a web development webinar and as a marketing initiative we send out emails to web developers. Below shown is the view of the Customer Journey. Step 1: First take a segment tile from the right toolbox panel and drag it on the canvas and we enter the name of the segment that we want to target. Here as stated earlier we have selected a target segment consisting of web developers. Note: The segment will appear only if it is in the “Live” state. Step 2: We drag and drop the Marketing Email tile, and then add a Marketing page in the Marketing email.  We have done this as we have added a link to a marketing page in our marketing email. Step 3: The marketing page designed is as shown below. When the users click on the link in the email they will be redirected to this page which contains a Marketing Form. Step 4: Then we add a trigger tile in the customer journey with the condition to check if the user has submitted the marketing form in one hour as shown below. If the user has registered in one hour then he/she will receive a “Thank You” email with the details of the webinar. And if the user has not registered within the given period of time he will receive another email which says visit us as www.cloudfronts.com to know more about us. Once the everything is set, the customer journey will begin at the specified Start time and accordingly end at the specified End time. Once the customer journey is run completely we can get a lott of insights regarding the events that took place. Step 5: We can go to the Marketing emails section and click on the insights option as shown in the pic below: Below shown are the insights generated: Similarly we can also view the insights generated for the Customer journeys. The below image shows the number of contacts on each of the tiles as they progressed throughout the journey. The arrows show that only 2 contacts out of 7 submitted the Marketing form and hence received the Event details while the rest 5 contacts received the “Visit Us” Marketing email. Conclusion: Using this feature we have a control of how we want our users to interact with the emails and hence generate more and more leads and also gain insights on the process as a whole.

Paging in D365 Customer Engagement v9.0

Posted On July 10, 2018 by Clinton D'Mello Posted in Tagged in

Introduction: The Xrm.retrieveMultipleRecords method is used to retrieve a collection of records in Dynamics 365 Customer Engagement . In this blog we will demonstrate how we can use paging and fetch more than 5000+ records. In CRM when we fetch records using code we only get the first 5000 records, in some cases there are more than 5k records that need to be fetched, we can achieve this using paging. In this blog for the demonstration purpose, we will fetch 3 records per page so that we can see how the paging functionality works in D365 v9.0 Implementation: Step 1: The syntax is as shown below: Xrm.WebApi.retrieveMultipleRecords(entityLogicalName, options, maxPageSize).then(successCallback, errorCallback); Here the in options parameter we specify the query. In our example we will be fetching all the accounts in the system. In the maxPageSize parameter we specify the number of records to be returned per page. By default the value is 5000. In this example we set the maxPageSize as 3 which will return 3 records per page. As the total number of records being fetched are more than 3, the nextLink attribute is retuned with the link to fetch the next set of records. The value of the nextLink attribute returned is already encoded. Before we pass the link to fetch the next set of records we have to make sure to only set the query in the options parameter. We also store all the values returned in a separate variable so that it can be used later. Step 2: The code is shown below. The allaccounts variable will store all the accounts fetched at the end as we keep on concatenating the received results. Code: var query = “?$select=name”; var allaccounts = null; var scripting = { retrieveMultipleContacts() { var url = Xrm.Page.context.getClientUrl() + “/api/data/v9.0/accounts”; Xrm.WebApi.retrieveMultipleRecords(“account”, query, 3).then( function success(result) { var resultRetrieved = result; allaccounts = resultRetrieved.entities.concat(allaccounts); if (result.nextLink != undefined) { console.log(“Next page link: ” + result.nextLink); query = result.nextLink; var splitValue = query.split(url); query = splitValue[1]; scripting.retrieveMultipleContacts(); } }, function (error) { console.log(error.message); } ); } } Step 3: To test this out we can simply trigger this code to run on the change of form fields and while debugging we can check the values returned and stored in the allaccounts variable. Conclusion: The new D365 v9.0 Xrm.WebApi.retrieveMultipleRecords method simplifies the whole process of fetching records using paging.

Download Doucument Templates using Console App

Posted On June 8, 2018 by Admin Posted in Tagged in ,

Dynamic 365 development services has a team of experts, D365 architects and developers who works closely in every step in the business while closely understanding the requirements and designing the right solution for the business according to the needs as far as development is concerned the development team has a set of experts and developers that coordinate closely with the client and by using standard microsoft development technologies like visual studio and TFS online a robust and concrete development process is strategised. After developing the application it is internally tested according to the business needs and submitted to microsoft in order to clarify any issues. After that the application is listed on the App Source. Introduction: In this blog we will be demonstrate how to download word document templates from D365 Customer Engagement and then import them to another environment. Often there are requirements to move document templates from one environment to another. But currently adding document templates to solutions is not supported.  To overcome this we have created a console app which downloads the word document template. Implementation: Step 1: To download Document templates we have created a Console App and it requires the following details: Username Password Organization Service Endpoint Address GUID of the template word template to download The username and password are the basic details that we use to log in to https//:www.portal.office.com To get the Organization Service Endpoint Address, navigate to Settings > Customizations > Developer Resources and copy the address as shown in the image below. To get the GUID of the Template Navigate to Settings > Templates > Document templates and open the template you want to download and Click on the Pop Out option at the top right as shown below Then from the URL we can get the GUID of the record as shown Step 2:  The code to download the document template is shown below. It downloads the Word template and stores it in the location specified in the code. Remember to change this location to the location on your PC. Note: Replace all the required values in the code according to your organization details. Code: using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Client; using System; using System.Net; using System.ServiceModel.Description; using System.Text; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Query; using System.IO; namespace DownloadDocumentTemplates { public class DocumentTemplateDownload { static IOrganizationService _service = null; static OrganizationServiceProxy _proxy = null; static void Main(string[] args) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ConnectToCRM(“test@test.onmicrosoft.com”, “pass@1234”, “https://test.api.crm8.dynamics.com/XRMServices/2011/Organization.svc”); Guid userId = ((WhoAmIResponse)_service.Execute(new WhoAmIRequest())).UserId; if (userId != null) { Console.WriteLine(“Guid: ” + userId); //GUID of the document template String documentTemplateId = “094EEB2A-948C-E711-8112-70106FAA45E1”; GetDocumentTemplateContent(documentTemplateId); Console.ReadKey(); } } public static void ConnectToCRM(string _username, string _Password, string _OrgSOAPServiceUri) { try { ClientCredentials credentials = new ClientCredentials(); credentials.UserName.UserName = _username; credentials.UserName.Password = _Password; Uri serviceUri = new Uri(_OrgSOAPServiceUri); _proxy = new OrganizationServiceProxy(serviceUri, null, credentials, null); _proxy.EnableProxyTypes(); _service = (IOrganizationService)_proxy; } catch (Exception e) { Console.WriteLine(“Error while Connecting: ” + e.Message); } } public static void GetDocumentTemplateContent(string documentTemplateId) { EntityCollection doc = null; string content = null; string documentTemplateName = string.Empty; Encoding encoding = Encoding.UTF8; try { string fetchXML = @”<fetch version=’1.0′ output-format=’xml-platform’ mapping=’logical’ distinct=’false’> <entity name=’documenttemplate’> <attribute name=’content’ /> <attribute name=’documenttype’ /> <attribute name=’name’ /> <attribute name=’status’ /> <attribute name=’modifiedon’ /> <attribute name=’modifiedby’ /> <attribute name=’description’ /> <attribute name=’languagecode’ /> <attribute name=’associatedentitytypecode’ /> <order attribute=’documenttype’ descending=’false’ /> <order attribute=’name’ descending=’false’ /> <filter type=’and’> <condition attribute=’documenttemplateid’ operator=’eq’ uitype=’documenttemplate’ value='” + documentTemplateId + @”‘ /> </filter > </entity > </fetch > “; doc = _service.RetrieveMultiple(new FetchExpression(fetchXML)); if (doc != null) { if (doc.Entities.Count > 0) { content = doc[0].Attributes[“content”].ToString(); documentTemplateName = doc[0].Attributes[“name”].ToString(); } byte[] textAsBytes = Convert.FromBase64String(content); File.WriteAllBytes(@”C:\Users\test\Desktop\” + documentTemplateName + “.docx”, textAsBytes); } } catch (Exception) { throw; } } } } Step 3: When the code is run it downloads the document template on the your PC and the document template is named after the template in CRM. Conclusion: This is very helpful as it can be used in another environment by simply uploading the template. To import the word template we can navigate to Settings > Templates >Document Templates and then upload the template.

Call Workflow directly from a button using Ribbon Workbench

Posted On May 25, 2018 by Clinton D'Mello Posted in Tagged in

Introduction: In this blog we will demonstrate how to call a workflow directly from a button without any custom JavaScript code. Implementation: Step 1: Create the required workflow. In this example i have created a  simple workflow on the opportunity and remember to select the  “As an on-demand process” option. Step 2: After the workflow is created store the GUID of the workflow. To get the GUID  select the workflow and copy down the ID from the URL as shown in the below image. Step 3: Now create the custom button on Opportunity entity using Ribbon Workbench. Step 4: Create a new Command and click on “Add Action>JavaScript Action” as shown in the image. Step 5: In the library option write the following “/_static/_forms/form.js” and in the Function Name field “Mscrm.FormAction.launchOnDemandWorkflowForm“. Then as shown in the above image add two Parameters as follows: Crm Parameter = PrimaryEntityTypeCode String Parameter = “GUID of the Workflow”. Step 6: For the final step add the command to the newly created button by simply selecting it from the drop down in the properties section. Step 7: Now when we click on the button that we created we get the following message. On clicking OK the workflow will run. This is a helpful as it can be done quickly without using any custom code.

Calling unbound actions using Xrm.WebApi in D365 v9

Posted On April 25, 2018 by Clinton D'Mello Posted in Tagged in

Introduction: In this blog we will be demonstrating how to call an unbound action using Xrm.WebApi which provides properties and methods to use Web API to create and manage records and execute Web API actions and functions in Customer Engagement The available methods are createRecord, deleteRecord, retrieveRecord, retrieveMultipleRecords,execute and executeMultiple.The execute method executes a single action, function or CRUD operation. Implementation: The syntax for execute method is as follows: Xrm.WebApi.online.execute(request).then(successCallback,errorCallback); Note: This method isn’t supported for Unified Interface and it is only for online mode hence we have to use Xrm.WebApi.online object to execute the method, else it will fail. Step 1: First we create an unbound action. Here in our example we have created an action with the name “new_ActionTest” and we have activated it. In the action steps we have written a step to create a new contact with the name “Jessy David”. Here in our action we an Integer parameter. Any steps can be added as required. Step 2: Below shown code is function used to call the unbound action. Here “boundParameter” parameter is an optional String parameter, we have specified it as null as our action is not bound to any entity. “operationName” is an optional String parameter which is the name of the action.“operationType” is an optional Number parameter which indicates the type of operation we are executing is an Action hence we have specified 0. We can specific 1 for Functions and 2 for CRUD operations. When we run this, the action is called and a new contact is created according to the steps mentioned.

Connecting to Dynamics 365 v9 “metadata reference cannot be resolved” issue fix

Posted On April 10, 2018 by Clinton D'Mello Posted in Tagged in

Introduction: In the blog we will be discussing about the error while connecting to Dynamics 365 version 9 using console app. Implementation: In our example we will show how to connect to Dynamics 365 using a Console app in v 8.2 and when the same code is used to connect to version 9 we get an error. We will also discuss about how to resolve the issue Step 1:  The code show below is used to connect to Dynamics 365 version 8.2 using Console App. Step 2: When we run the above code, we get the following output. Step 3: Now we change the credentials and try connecting to Dynamics 365 v 9 with the same code, we get the following error. Step 4: To solve this issue there are two ways, in the first method, set the Target framework to “.NET Framework 4.6.2 or above”. Step 5: After changing the target version build the solution again and run the app.The connection to Dynamics 365 version 9 environment will be successful. Step 6: The second method is by using the below code before making a connection. TLS stands for “Transport Layer Security,” and is a protocol that is an industry standard designed to protect the privacy of information communicated over the Internet.

Email Migration from D365 CRM v8.2 to D365 CRM v9 using TIBCO Cloud Integration: Activity Parties

Introduction: In this blog, I will detail how to migrate Activity Parties of Emails from one CRM to another. In my previous blog, I outlined the first step of the Email migration process which is migrating the body of the email. Migrating the corresponding Activity Parties of an Email is the second step of this process, as the Email body now exists in the Target CRM. What are Activity Parties? Other than the Body, an Email Activity consists of: Sender: The person(s) sending the email. Recipient: The person(s) receiving the email. CC & BCC: The person(s) that are copied in the email. Owner: The person who is the owner of the email. Regarding: This generally links to an entity in CRM which pertains to the email. For example, a Case or a Project in CRM. ‘Sender’, ‘Recipient’, CC’, ‘BCC’, ‘Owner’ and ‘Regarding’ are each stored in CRM as a separate Activity Party of that email with a ‘Participation Type’ code (field name: ‘participationtypemask’) to establish the field that specific party belongs to i.e. 1 = Sender, 2= To Recipent and so on (as shown below). Generally, in an Activity Party, the person(s) are either System Users or Contacts. This is specified in the field ‘partyobjecttypecode’ as shown above. Keeping this in mind, one can lookup to these entities to obtain the corresponding GUIDs in the Target System and map it as the ‘partyid ‘. After the Activity Party is created, the owner of the Activity Party should be updated as per its owner in the Source environment. The ‘Owner’ Activity Party is automatically created by CRM as the same User as the Owner of the Email (configured when you migrate the Email Body in Step 1). The ‘Regarding’ Activity Party links to a Case/ Project and not a ‘person’, however, the same logic applies i.e. map the required GUID and its type. Migrating Activity Parties is not as complicated once understood. Unfortunately, not much is easily available online about this. I hope this blog demystified a few concepts about Activity Parties of an Email and how they can be migrated from one CRM to another. My next blog will detail how to migrate Email Attachments and update the status of an Email.

SEARCH :

FOLLOW CLOUDFRONTS BLOG :

[gravityform id="36" ajax="true"]

FOLLOW CLOUDFRONTS BLOG :