
I have added an HTML Button as a Web Resource to my form.
How do I add an onClick event to trigger a function on the Form Properties js.
Web Rescource
<html><head>
<style>
.button {
background-color: #4CAF50;
border: none;
color: white;
padding: 5px 12px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
.button {
border-radius: 8px;
}
</style>
</head> <body>
<button class="button"> Submit </button>
</body></html>
1. Add an onclick to your button
<button class="button" onclick="MyFunction()"> Submit </button>
2. Add the function and do stuff you want to do
<script>
function MyFunction() {
//Do whatver you want
//For example if you want to read the value of a text field on the form
let fieldVal = window.parent.Xrm.Page.getAttribute("myFieldName").getValue();
//You want to get the ID of the record
let guid = window.parent.Xrm.Page.data.entity.getId();
}
</script>