I am working with a button on the ribbon of a grid view. I have accessed the field I want to fire the onChange event with using Xrm.WebApi.retrieve record to the get the field. Everything is working well, however, I am trying to figure out the correct syntax to use the fireOnChange() method.
function getIds(selectedItems) { for (var item in selectedItems) { if (selectedItems.hasOwnProperty(item)) { fetchData(selectedItems[item].Id); } } } function fetchData(appointment_id) { Xrm.WebApi.retrieveRecord("appointment", appointment_id, "?$select=_regardingobjectid_value,new_generatemessage").then( function success(results) { var generateMessage = results["new_generatemessage"]; var clientId = results["_regardingobjectid_value"]; Xrm.WebApi.retrieveRecord("contact", clientId, "?$select=firstname").then( function success(clientResults) { var name = clientResults["firstname"]; }); }); }
I highlighted the field that I want to attach the fireOnChange() method to. I want to do this because I have another script attached to that field. So I'm hoping that this button on the ribbon will trigger the onChange that will fire the other code. If this doesn't work, I'll try putting the other code directly into this script so it can be run on the button press. Any thoughts of how I can do this? Thanks.
*This post is locked for comments
Hi Ben,
Suggest you to check the difference between client side events and server side event in dynamics 365.
It will help you to understand where to use JS and where to use plugins and custom workflows.
docs.microsoft.com/.../client-scripting
Nijo
Hope this helps
Palani,
Thanks for the response, very helpful. I have a couple questions
1) do you have a link to Microsofts documentation on the update and retrieve functions? When I was digging around on this problem before coming I didn't see anything specifically on the syntax of using these function.
2) For on demand workflow - this would be great but I think for the complexity of the task we will need to use a custom workflow activity, and I am much more comfortable with javascript than .NET code.
3) You say the other option is using "an action" - what do you mean by this? Never heard of this one. Like a plug in?
Hi Ben,
No, you cannot use JavaScript in a workflow. You definitely cannot call the same form-side JavaScript as is and make it work from the grid because the functions getvalue, setvalue, fireonchange are all form-specific functions. So, one option is you need to modify your onchange javaScript function to make use of Retrieve and update functions if you want to use it from a grid. The other option is using an on-demand workflow or an action.
Regards,
Palani
Pravin,
What do you mean update method? What I want to do is something like:
var generateMessage = results["new_generatemessage"];
generateMessage.fireOnChange()
However, I don't need the results, I need the actual field. And I don't know what the equivalent to "Form context" is when working with a grid, or if there even is such an equivalent.
Firas,
Would this work from the grid? The problem is that field being changed triggers a bunch of javascript. If I try to replace the javascript with a workflow, I will need to rewrite lots of code. This may be my only option, but hopefully I can find a better way.
Palani,
Can I put javascript code in an on demand workflow?
Hi Ben T,
I believe, you need to use update method to call another js function.
Hello,
It is better to call an on-demand workflow from the button that will modify the field and replace the script that triggers the change with another workflow that triggers when this field is modified.
Regards,
Firas ROUATBI
Hi Ben,
You won't be able to trigger on change event or any form side events from a grid view. You might need to consider updating the field using Xrm.WebApi.Update method and trigger the necessary logic from a plugin or workflow (or) directly trigger an on-demand workflow on the selected record where the on-demand workflow contains the necessary code.
Regards,
Palani Babu
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156