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

Announcements

No record found.

News and Announcements icon
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,218 User Group Leader on at

    Hi,

    Please share the old code using xrm.page

  • Verified answer
    Bipin D365 Profile Picture
    28,985 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 62 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans