java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.
java script code to set a field called submit of data type as Two option set to yes on click of the ribbon submit button.
Hi Richa,
I think you are not passing the PrimaryControl as parameter that's why you you are getting that error. Please follow the steps below and hopefully you are able to resolve the issue.
Select the CRM Parameter.
Select the Primary Control
Here is the JS function for your reference.
function SetSubmitValue(primaryControl) { var formContext = primaryControl; formContext.getAttribute("new_submit").setValue(true); }
Hope this helps
Best Regards
PG
the correct thing to do is the following :
First your javascript method should have the argument formContext rather than executionContext for ribbon workbench.
The code will be the following :
function OnSubmit(formContext) { formContext.getAttribute("atci_submit").setValue(0); }
The second thing to do in your ribbon workbench, go to the command of your button and add the primaryControl as a parameter to your javascript method.
This should resolve your problem. Good luck
Hi Pankaj,
Thanku for your reply.
yes, i am getting the error like " Cannot read property 'getFormContext' of undefined"
so the ask from me is the below one:
Add a custom ribbon button called "Submit" and place it on Travel Plane form after new button.(done)
On Click of the button, the submit field on the form should set to yes.
Add a Jscipt called atci_/Scripts/TravelPlan.OnLoad.js. Write a script to set the Submit field to Yes.
Call that Script on click of submit button.
Regards,
Richa
Hi,
If you are calling this function on click on ribbon button then you will not get executionContext automatically.
Check below article on how to get formContext from ribbon workbench.
blog.magnetismsolutions.com/.../getting-dynamics-365-formcontext-from-ribbon-workbench
Hi Richa,
you should change the setValue(0) to setValue(false);
it will not return anything so your const value will be undefined. How are you calling this function and what are you trying to return?
You also need to pass the executionContext. In case of Ribbon button you need to pass the CRM Parameter of Primary Control.
Best Regards
PG
Hi Pankaj,
i am using the below piece of code, but it is getting error out.
as i am new to javascript so not sure where i am wrong.
function OnSubmit(executionContext)
{
var formContext=executionContext.getFormContext() ;
const value = formContext.getAttribute("atci_submit").setValue(0);
return value===true;
}
Regards,
Richa
Hi,
You can use the value or label.
Xrm.Page.getAttribute("field").setValue(0); or formContext.getAttribute("field").setValue(0); Xrm.Page.getAttribute("field").setValue(true);
Hope this helps
Best Regards
PG
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,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156