Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Facing difficulty with the work of "save" button

Posted on by Microsoft Employee

There are two field in the account form named "gst no" & "pin code". we have added a java script code where it will check that "gst no" & "pin code" is already exists or not in the accounts database if it already exists then the field value will be blank against on change event,this code is running successfully,so after the on change event code running successfully the value of those field remains blank but when we click the "save" button it is getting saved.But we want to restrict the "save " button here only. Our requirement is if the "gst no" & "pin code" value remains blank then the form will not be saved. i'm attaching the code which i have written against "on save" button.

function fnTest(econtext)

{

var Cat1 = Xrm.Page.getAttribute("new_gstno").getValue();

var Cat2 = Xrm.Page.getAttribute("address1_postalcode").getValue();

if(Cat1==null && Cat2==null)

{

if(econtext != null && econtext.getEventArgs() != null)

{

alert("Please Provide a different GST Number and Pin code");

var eventArgs = econtext.getEventArgs();

if(eventArgs.getSaveMode() == 1 || eventArgs.getSaveMode() == 2 || eventArgs.getSaveMode() == 70)

{

eventArgs.preventDefault();

            }

         }

     }

}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Facing difficulty with the work of "save" button

    i know this sir,already one code is running on change to prevent the duplicate entry and if duplicate entry will be there then that two particular field value will be blank.I want that java script which will prevent to save the details when that two particular field will be blank.

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    Dynamics365 Rocker 7,755 on at
    RE: Facing difficulty with the work of "save" button

    Make both fields mandatory. There is no need of Java Script.

    If there is business restriction to make these fields mandatory then use Business rules.

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Facing difficulty with the work of "save" button

    Hi,

    It looks like that you need to make the 2 fields mandatory. You don't need to write a javascript for this, simply make these field business required and the error message will appear automatically on save.

    If you don't want to make field mandatory then you can create a business rule and make the field mandatory.

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans