Tag Archives: dynamics 365 javascript
Triggering Custom Action Without Modifying the Record in Dynamics 365 using JavaScript
In Dynamics 365, custom actions allow you to perform specific business logic, such as sending emails, making calculations, or calling external services. Often, these actions are triggered based on field updates or changes to records. However, there may be situations where you want to trigger a custom action through a button click, without modifying any record fields or triggering unnecessary updates. In this blog, we’ll explore how to use a button to trigger a custom action for a creating a specific task record in Dynamics 365 using JavaScript, that too, without modifying the record. Here’s the JS code used to trigger the action: Attach the JavaScript function to the button ‘Create Task’ event of the Case form, so that every time a case is created, the follow-up task is automatically generated. Click on the ‘Create Task’ button. And here, we have the follow up task created. Happy Developing! We hope you found this blog useful, and if you would like to discuss anything, you can reach out to us at transform@cloudfonts.com.
How to Use Solution Checker to identify usage of the OrganisationData.svc endpoint (Odata Deprecation for Web resources)
The Organization Data Service is an OData v2.0 endpoint introduced with Dynamics CRM 2011. The Organization Data Service was deprecated with Dynamics 365 Customer Engagement v8.0 in favor of the Web API, an OData v4.0 service. For more details please follow the link https://powerapps.microsoft.com/en-gb/blog/odata-v2-0-service-removal-date-announcement/ OData v2.0 Service removal date announcement | Microsoft Power Apps To determine the deprecation in your old javascripts below is the blog you can refer to. Step 1: Log in to the required Power Apps environment using the URL make.powerapps.com by providing a username and password and select your environment accordingly. Step 2: Go onto Solutions and click on [+ New solution] from the menu bar Step 3: Name your Solution and fill in all the details which include the Publisher as well as the Version details. Step 4: Go inside your solution and select Add existing option. Click on More and select Web resource. Step 5: Search for your web resources using your custom publisher. For example, your publisher might be new_ or abc_ and so on.It depends on how you name your publisher. Step 6: Select all the web resources you required and once done, go back to the solution and click on the ellipses(3 dots) of your solution. Click on the option Solution checker and select Run. Step 7: We can also view the Run Status of the solution. Step 8: Click on Ellipses(3 dots) again of the solution you have worked on and click on Solution checker and then you can view the option Download results. Click on that option and once you download it, it will be downloaded in the form of xlsv(excel). Try searching the issue for web-avoid-crm2011-service-data on that excel sheet. Hope this helps!!!
Dynamically filter required Fields/Columns from a Record’s BPF and Form and apply Requirement to those fields
Hi Everyone, Let me explain this topic with an example of a scenario that you might encounter. I’ll walk you through how to complete this scenario in a concise manner below. Use Case Let’s say you have a Table (Entity) with or without multiple Business Process Flows (BPFs) that include some required Fields and even on the Form. Even if the required fields are empty and you want to change a field or flag within the form and save the record. We must disable all required Fields on the Form and then re-enable the requirements for those fields. We can do this with some simple JavaScript code. Step 1: Find a trigger point for your JS function to be called.It can be done with a Ribbon Button or by manually changing a Field. Find the code you’ll need below. I’ll be using Ribbon Button to trigger my JS Function. Quick Tip: You cannot get any Attribute Value of a Field residing in BPF directly. You need to get the entire Control of the Field and then call its attribute values. Step 2: Register your JS function onto your Ribbon Workbench or OnChange of any Field on Form. Since I called my function using Ribbon Button, I used “OpportunityForm.executeMain” with Parameters; “CRM Parameter -> Primary Control“ If you’re calling the JS using Field OnChange, then register the function as “OpportunityForm.executeMain” and do pass ‘executionContext‘. In this case, your part of the script will change as below (use this if you use JS on your Form only) OUTPUT This is how all fields will have no requirement on the Form. I took this output before re-enabling the requirement level for the fields. That’s all, I hope this helped you
Hide And Show a Field in Dynamics 365 CRM Using JavaScript
Introduction: In Dynamics 365, you can hide and show fields using JavaScript. This is useful if you have business logic that determines if fields are displayed or not to the user. Implementation: Let’s take an example where you would like to hide the Account field if the Contact field is populated. Next, we can check if the Contact field is empty using getAttribute(“fieldname”).getValue(). If empty, we can hide the field using setVisible. Let’s add this to the change event of the Contact field: function showAccountOnChange(executionContext){ formContext = executionContext.getFormContext(); if (formContext.getAttribute(“parentcontactid”).getValue() == null) { formContext.getControl(“parentaccountid”).setVisible(false); } else { formContext.getControl(“parentaccountid”).setVisible(true); }} When Contact field is populated, the Account field is displayed: When empty, the Account field is hidden and the field collapses (note this is v9 Dynamics 365): Hope this helps …
Get Time in Hours and Minutes from a Date Field in CRM using JavaScript.
D365 gives a functionality to create a Date and Time field where in you can provide the user to select the date or both date and time. But what if you just need the time in Hour and Minutes format from the selected date in the Date field, This can be achieved using a JavaScript. In this blog lets see how we can get the time entered in the date and time field and format it in hours and minutes format. I have created a field in CRM with field type Date and time. Here is how it looks Using the JavaScript “Date” functions you can get the Time entered in the date and time field as shown below. This code gets the date and time (hours and minutes) selected in the date field and will format the hour and minutes in the format “HH:MM“. Hour – (getHour()) Minutes – (getMinutes()) Output – Note : You can also add the AM / PM to the time string I have not added it in my time string “strTime” but have stored the value of it in “ampm“. Hope this helps !
Get Month | Day | Year from a Date field in CRM using JavaScript.
D365 gives a functionality to create a Date and Time field where in you can provide the user to select the date or both date and time. But what if you need just the month from the selected date in the date field or say the date or year from the selected date in the date field, This can be achieved using a JavaScript. In this blog lets see how we can split or get the Month | Day | Year from a selected date in the CRM Date and time type field. I have created a field in CRM with field type Date and time. Here is how it looks Using the JavaScript “Date” functions you can get the Month | Day | Year and Time of the entered date as shown in the below script. This code gets the date selected in the date field and splits the date into Month – (getMonth()) Note : January – December is (0-11) hence add 1 so make it (1-12). Day – (getDate()) Year – (getFullYear()) This code gives the month date and date in 2 digit format i.e. if the date is a single digit say 9 it will give it as 09. You can further use this according to your requirement either to change the date format or for many other date related customizations. Hope this helps !
Why Custom Filter JS code doesn’t work on Lookup field? [Fixed]
One of the major pet-peeve is not understanding why the code isn’t working. And you for sure know you’ve written the correct code. But, thing just don’t work. One such tricky situation is that of applying custom filter to fields using JavaScript in Dynamics 365 Customer Engagement apps. Scenario Let’s say you have a custom filter to be applied to a field and you’ve written your JS code on Load to apply the filter and everything (you know what you need to do!) Example: But the above is just not working. Why??? Reason The reason is pretty simple! Because, the Lookup field is still using the one set on the field itself. Check that – The above should be turned off to make your code work since the field’s default OOB filtering takes precedence. And now, your code should work (Provided everything in it correct) Hope this quick tip helps!
Set Lookups in Xrm.WebApi D365 v9 correctly
Using Xrm.WebApi needs you to be careful with the field names and what to use when. Especially, when you are dealing with Lookups. One of the most common errors you’ll come across is the one like below – “An undeclared property (fieldname you entered) which only has property annotations in the payload but no property value was found in the payload.” This is confusing as to what needs to be put in while setting the lookup. If you have done the below, entered the name of the field which is all in small caps – object[“msdyn_resourcerequirement@odata.bind”] = “/msdyn_resourcerequirements(<Guid>)”; This will result in the above error!!! You’ll need to put the Schema name of the lookup field instead and this should solve your problem – and the code should look like this – object[“msdyn_ResourceRequirement@odata.bind”] = “/msdyn_resourcerequirements(<Guid>)”; And this should totally work for you!! Hope this helps! 🙂