Crm 2011 on premise

I have lead form in Dynamics CRM. In javascript, how can I capture SAVE button event in CRM? The save button is on the top of the CRM. Basically, all i need is when someone click on save button, it will validate one field called 'firstname' and ensure it has value.

That's all.

Thanks
LVL 1
ITsolutionWizardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott FellDeveloper & EE ModeratorCommented:
While many of us may not have access to MS Dynamics, it is possible that we can at least help you with the js part.

See if this example helps

http://jsbin.com/vorubuxoli/edit?html,output
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>29069742</title>
</head>
<body>
<form>
  <input id="txtFirstName" name="firstname">
  <button id="btnSubmit">Submit</button>
  </form>
  <script>
    document.getElementById("btnSubmit").addEventListener("click", function(){
     
    var firstName = document.getElementById("txtFirstName").value;
    if(firstName.length == 0){
      alert("please fill in the First Name Field");
    }
});

  </script>
</body>
</html>

Open in new window

ITsolutionWizardAuthor Commented:
Are u sure the submit button name is the one u wrote?
Because I don't know how to find it.
Scott FellDeveloper & EE ModeratorCommented:
I have no idea. I am just creating an example.

Can you post the code you are working with?
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Feridun KadirPrincipal ConsultantCommented:
You'll need to add your JavaScript function to a web resource (in CRM) and then link that web resource to the lead form and then associate the JavaScript function to the form OnSave event. This article on MSDN has more details: https://msdn.microsoft.com/en-gb/library/gg334481(v=crm.5).aspx

But wouldn't it be easier just to make the first name field required? You can do this on the definition of the first name field in the customization area.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ITsolutionWizardAuthor Commented:
make one field require is just step one. I have more thing to do with that.
Overall, I need to know the SAVE button name and make click button validator. If you work with crm, you will know the save button is always on the top ribbon. not inside of the web form.
Feridun KadirPrincipal ConsultantCommented:
Yes I know where the Save button is!

Please review the link I posted in my earlier comment. That describes how to write JavaScript that will be run when a user clicks the Save button. You don't need to know or use the SAVE button name.
ITsolutionWizardAuthor Commented:
I don't see it
Feridun KadirPrincipal ConsultantCommented:
What is it that you don't see? The link?
Scott FellDeveloper & EE ModeratorCommented:
I am not familiar with ms dynamics and just trying to help.  

After some research, it looks like you just need to create a javascript function, then in your workbench attach the function to an action such as save.

https://community.dynamics.com/crm/b/microsoftdynamicscrmandstuff/archive/2016/01/13/web-api-executing-custom-action-via-javascript
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Dynamics

From novice to tech pro — start learning today.