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

  • Community Member Profile Picture
    on at
    RE: 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

    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]

  • Verified answer
    Bipin D365 Profile Picture
    28,961 Moderator on at
    RE: 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

    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/

  • Verified answer
    meelamri Profile Picture
    13,212 User Group Leader on at
    RE: 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

    Hi,

    Please share the old code using xrm.page

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,272 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,931 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans