Hello,
I have a single line of text field called 'A'. In this field I want to insert/update only numbers. What would be the best way for this? If you have the code can you please share?
Current CRM version : 2015
*This post is locked for comments
Hello,
I have a single line of text field called 'A'. In this field I want to insert/update only numbers. What would be the best way for this? If you have the code can you please share?
Current CRM version : 2015
*This post is locked for comments
Ah! it should not be onsave , s attach onchange of accountnumber field.
As mentioned, my field name is test_accountnumber. Below is the code I kept in form for onsave. I dont see any issues with the field name
function OnChangeAccountNumber() {
var accountNumber = Xrm.Page.getAttribute("test_accountnumber").getValue();
if (accountNumber !== null && accountNumber !== "") {
if (isNaN(accountNumber)) {
Xrm.Page.getAttribute("test_accountnumber").setValue(null);
Xrm.Page.getControl("accountnumber").setNotification("Please enter only numbers", "CHKNUM");
}
else {
Xrm.Page.getControl("test_accountnumber").clearNotification("CHKNUM");
}
}
else {
Xrm.Page.getControl("test_accountnumber").clearNotification("CHKNUM");
}
}
Please check field name
Now it is throwing error as unable to get property set notification of undefined or null reference
Try with this , Please make sure the field name is correct highlighted below I did the changes .
function OnChangeAccountNumber() { var accountNumber = Xrm.Page.getAttribute("accountnumber").getValue(); if (accountNumber !== null && accountNumber !== "") { if (isNaN(accountNumber)) { Xrm.Page.getAttribute("accountnumber").setValue(null); Xrm.Page.getControl("accountnumber").setNotification("Please enter only numbers", "CHKNUM"); } else { Xrm.Page.getControl("accountnumber").clearNotification("CHKNUM"); } } else { Xrm.Page.getControl("accountnumber").clearNotification("CHKNUM"); } }
My field name is test_accountnumber. When I place this code, it is throwing error as unable to get property clear notification of undefined or null reference. Can you provide the code?
function OnChangeAccountNumber() {
var accountNumber = Xrm.Page.getAttribute("test_accountnumber").getValue();
if (accountNumber !== "") {
if (isNaN(accountNumber)) {
Xrm.Page.getControl("accountnumber").setNotification("Please enter only numbers", "CHKNUM");
}
else {
Xrm.Page.getControl("accountnumber").clearNotification("CHKNUM");
}
}
else {
Xrm.Page.getControl("accountnumber").clearNotification("CHKNUM");
}
}
This is alternate solution for onkkeypress in CRM 2015. Its depends on your requirement whether you go for onchange or onkeypress.
If your customer agreed with onchange behavior go for Ravi's suggestion .
Thanks Goutam. In your post, you mentioned it as unsupported way. Can we still use it?
Both code will work . In have already shared you can try my second suggestion which will work for keypress event which means you cant type other characters except numeric. Just put the code in the webresource you dont need to attach the forms anywhere just replace the field name,
Ravi's suggestion will also work , it will fire onchange event , so attach the function in onchange event.
Goutam,
which code will work effectively to check the number for single of text field. Is it your's or Ravi's?
If it is your code, can you provide the code for it please? Somehow When I use your code it is throwing error for addonkeypress? If you can provide code for the field 'A' , that would be great
André Arnaud de Cal...
292,516
Super User 2025 Season 1
Martin Dráb
231,321
Most Valuable Professional
nmaenpaa
101,156