Crm 2011 on premise

ITsolutionWizard
ITsolutionWizard used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
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

Author

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 Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
I have no idea. I am just creating an example.

Can you post the code you are working with?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Principal Consultant
Commented:
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.

Author

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 Consultant

Commented:
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.

Author

Commented:
I don't see it
Feridun KadirPrincipal Consultant

Commented:
What is it that you don't see? The link?
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial