Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

fireOnChange() triggered by button on the ribbon

Posted on by 777

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

  • Suggested answer
    Nijos Profile Picture
    Nijos 1,672 on at
    RE: fireOnChange() triggered by button on the ribbon

    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/.../events

    docs.microsoft.com/.../client-scripting

    carldesouza.com/.../

    www.powerobjects.com/.../

    Nijo

    Hope this helps

  • Ben T Profile Picture
    Ben T 777 on at
    RE: fireOnChange() triggered by button on the ribbon

    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?

  • Palani Profile Picture
    Palani 196 on at
    RE: fireOnChange() triggered by button on the ribbon

    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

  • Ben T Profile Picture
    Ben T 777 on at
    RE: fireOnChange() triggered by button on the ribbon

    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.

  • Ben T Profile Picture
    Ben T 777 on at
    RE: fireOnChange() triggered by button on the ribbon

    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.

  • Ben T Profile Picture
    Ben T 777 on at
    RE: fireOnChange() triggered by button on the ribbon

    Palani,

    Can I put javascript code in an on demand workflow?

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: fireOnChange() triggered by button on the ribbon

    Hi Ben T,

    I believe, you need to use update method to call another js function.

  • Suggested answer
    Firas ROUATBI Profile Picture
    Firas ROUATBI 20 on at
    RE: fireOnChange() triggered by button on the ribbon

    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

  • Suggested answer
    Palani Profile Picture
    Palani 196 on at
    RE: fireOnChange() triggered by button on the ribbon

    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans