web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

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

(0) ShareShare
ReportReport
Posted on by

The 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?

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: "Your Request has been successfully raised !!", title: "Confirmation" };
var alertOptions = { height: 120, width: 260 };
if (formContext !== null) {
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
}
}

when i used in onsave event it was working but used executioncontext.getFormContext();

but now i removed from onsave and added same code but used primaryControl.getFormContext(); 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 have the same question (0)
  • Verified answer
    meelamri Profile Picture
    13,216 User Group Leader on at

    Hi,

    Please share the old code using xrm.page

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    I don't see any code to check if required fields have value in your JS code.

    if (formContext !== null) {

    Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);

    }

    you are only checking if formcontext is not null but you will also need to check if required fields has value in it.

    I think you need to modify your code to add check condition.

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Community Member Profile Picture
    on at

    Thank you so much for the quick response Medhi El Amir and  Bipin Kumar

    i used below code and it worked perfectly [ i had four required field ]

     setFieldValue: function (primaryControl) {

       var formContext = primaryControl;

       formContext.getAttribute("azmdc_assessmentsubmited").setValue("Assessment Submitted button clicked");

       var alertOptions = { height: 120, width: 260 };

       var alertStrings = { confirmButtonLabel: "", text: "Your  Request has been successfully raised !!", title: "Confirmation" };

       if(formContext.getAttribute("azmdc_productname").getValue() !== null && formContext.getAttribute("azmdc_intendedusefunctionality").getValue() !== null && formContext.getAttribute("azmdc_intendeduseenvironment").getValue

       {

           Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);

       }

    },

    just had a quick question thought, im using this code in  custom save button ,if i want to go back once user clicks on "OK" in alert , what code i need to add?   [ didnt use save and close button because alert will not wait till users clicks on ok, it will just navigate to back within 3 sec]

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 137 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 57

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans