Hi,
In my Dynamics environment, I have created a custom entity 'Car', that has two custom form fields:
I have also created a custom button, in Ribbon Workbench, on the Car entity, which calculates the amount in the target currency, when the source currency is taken as an input.
Note: I have installed Ribbon Workbench directly on Dynamics 365 interface, not XrmToolBox.
For this, here is the sequence of steps that I've used:
I have followed the exact same steps as per the documentation available. Which means:
The custom button is linked to the command, which in turn calls an action.
Within the action, my web resource is registered. The primary control is passed as the execution context.
But while attempting the above, I came across the following problem:
On click of the ribbon button, my JavaScript is not getting called. Nothing is happening. I am neither getting an error, nor the desired output.
Is there any reason behind this? Because when I tried registering another JavaScript on the account entity form, the script is successfully being called, on button click.
Therefore, I had a doubt whether my script is correct. It turns out, when I register my script using 'OnSave' event, the script runs perfectly with the correct output.
Here are the screenshots:
ACCOUNT ALERT button works perfectly
FIND INR COST button unable to call JS file
Has anyone come across a similar issue while using Ribbon Workbench?
If I follow the same steps on XrmToolBox instead, will it make a difference?
Would be really helpful if anyone could suggest a solution.
Thanks and Best Regards,
Tanmay
For any future Ribbon Button I would suggest start using new Power App functionality
learn.microsoft.com/.../use-command-designer
OOB and I found it very easy to use. You can use either FX or JScript.
The only downside is that for current release, you can only add new Button and not remove the OOB buttons.
Hi,
Yes we don't need getFormContext when you pass Primary Control as parameter from ribbon but you do need when you attach your javascript function on onload/onchange.
Hi,
Thank you so much for your help!
I've made the necessary changes in my JS code, as suggested, and now it runs perfectly, on button click.
Would be really helpful to know why the syntax works.
Any reason why the getFormContext() method should be removed, when ribbon button is the trigger?
But in the case where JS is invoked either OnSave/OnLoad/OnChange, I have to add getFormContext().
Thanks!
Best Regards,
Tanmay
Hi,
Replace below line of code
Var formContext=executionContext.getFormContext();
With
Var formContext=executionContext;
Here is the JS code:
var CalculateTotalCostInr =
{
SetTotalCostInr: function(executionContext)
{
debugger;
"use-strict";
var formContext = executionContext.getFormContext();
var totalCostUsd = formContext.getAttribute("tanm_totalcostusd").getValue();
var exchangeRate = 82.26;
var totalCostInr = totalCostUsd * exchangeRate;
formContext.getAttribute("tanm_totalcostinr").setValue();
alert(totalCostUsd);
}
}
Seems likes there isn't an issue with the syntax, since my script works when I add it on OnSave event. The only time when it doesn't run, is when I try to call it via the ribbon button.
I'll try removing and then re-adding the button, as suggested.
Best Regards,
Tanmay
Hi,
Can you please add debugger in your code.
Add alert in your code at the very first line.
Try to Delete Action from command and recreate again
I hope you don't have any syntax error in your code.
Please share your js code
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