Announcements
i want to update a field when users click on custom button and i have a below js code on dynamics 365 form works if i use Xrm.Page.getAttribute but since it is deprecated i used formContext.getAttribute and it is not working,formContext.getAttribute it will work only if add in Onsave or onloadof the form, which i don't want, because i want to update the command when users clicks on particular button and not when form saves
below code works perfectly [ cant use because it is deprecated]
setFieldValue: function () {
Xrm.Page.getAttribute("azmdc_assessmentsubmited").setValue("Assessment Submitted button clicked");
this code will work only if i add to onsave or onload , not on custom ribbon button.
setFieldValue: function (executionContext) {
var formContext = executionContext.getFormContext();
formContext.getAttribute("azmdc_assessmentsubmited").setValue("Assessment Submitted button clicked");
}
when i used in onsave event it was working but used executioncontext.getFormContext();
but now i removed from onsave and added directly to the custom ribbon button and alert will pop up but if I dont fill the req field and Click on button, alert will still pop up which i dont want
I notice that you have created a new thread regarding the new issue. Could you close this thread by checking my answer? thanks !
I'm sorry, I can't understand. Did you register the same function in the onSave event?
Hello Mehdi,
The above code worked perfectly .
I also had alert function in the onsave of the form and it was working fine, but after adding to the ribbon button, the alert will pop up even if required fields are not filled, if i click on button and if req field is not filled, still the alert will pop up? do i need to modify my below code?
[also created new post for this - I had alert function in the onsave of the form and it was working fine, but after adding to the ribbon button, the alert will pop up even if required fields are not filled - Microsoft Dynamics CRM Forum Community Forum]
setFieldValue: function (primaryControl) {
var formContext = primaryControl;
var formContext = primaryControl.getFormContext(); //before i used executioncontext.getFormContext();
formContext.getAttribute("assessmentsubmited").setValue("Assessment Submitted button clicked");
var alertStrings = { confirmButtonLabel: "", text: "You Request has been successfully raised !!", title: "Confirmation" };
var alertOptions = { height: 120, width: 260 };
if (formContext !== null) {
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
}
Hi,
You need to use primaryControl as formContext
setFieldValue: function (primaryControl) {
var formContext = primaryControl;
formContext.getAttribute("azmdc_assessmentsubmited").setValue("Assessment Submitted button clicked");
}
Good Luck !
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156