- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2024 01:12 PM
I have a requirement to add a pin field on the user table, I used a client script to control the accepted character in the field to be numeric but when I added the same field to the service portal view and I navigate to service portal profile page to input data. This field accept string data even though the accepted character is only numeric.
The above picture is the user table field and this field only accept numeric only.
The picture above is the service portal view which accept alphabet which is not meant to.
Please how can I make the service portal field to act exactly the same as the back end field?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 09:56 PM
Understood your issue now. Tried reproducing it on my PDI and you're right. The client script is not working when we make an update from Service Portal. It's may be as the update is happening via the User Profile widget. To overcome this, I tried creating a Before Insert or Update Business rule and it is working as expected. Refer below steps :
1. Make a Before Insert/Update Business rule as shown below and with the script as :
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var pinId = current.u_pin_id;
// Check if the value is not exactly 5 characters
if (pinId.toString().length != '5' || isNaN(pinId) == true) {
// Display an alert message
gs.addErrorMessage('Pin ID must be 5 numeric numbers.');
current.u_pin_id = '';
}
})(current, previous);
2. Navigate to Service Portal -> User Profile. Try Updating the pin with wrong input. It will give the below error message and will clear the Pin field value :
Please give this a try. Also, ensure that you mark your On-Submit Client Script In-active to avoid collisions.
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 06:08 AM
Can you please let me know the data type of your variable ? I tested your client script on my PDI with string data type and it is working as expected.
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 06:26 AM
That sounds weird. My data type is a string data type.
The issue i am having is that, if you add that field to the service portal view on the user table and navigate to service portal and click on your profile. You will find the Pin field but when you input any data it will accept it. Please see below screenshot from my PDI.
1. Here is the user table view
2. Goto view and select the service portal view. Add the field with configure layout to the field. This will make the field appear on the service portal profile page.
3. Tried saving record on the same service portal view in the backend and the client script works.
4. Goto service portal and click on your profile page at the upper right.
5. Try inputting any character of your choice and you will see that it will save and also show the new characters in the field on the user table even though its not meant to save any non-numeric characters.
6. Here is the view after saving on service portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2024 09:56 PM
Understood your issue now. Tried reproducing it on my PDI and you're right. The client script is not working when we make an update from Service Portal. It's may be as the update is happening via the User Profile widget. To overcome this, I tried creating a Before Insert or Update Business rule and it is working as expected. Refer below steps :
1. Make a Before Insert/Update Business rule as shown below and with the script as :
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var pinId = current.u_pin_id;
// Check if the value is not exactly 5 characters
if (pinId.toString().length != '5' || isNaN(pinId) == true) {
// Display an alert message
gs.addErrorMessage('Pin ID must be 5 numeric numbers.');
current.u_pin_id = '';
}
})(current, previous);
2. Navigate to Service Portal -> User Profile. Try Updating the pin with wrong input. It will give the below error message and will clear the Pin field value :
Please give this a try. Also, ensure that you mark your On-Submit Client Script In-active to avoid collisions.
Thanks and Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 06:45 AM
Thank you. This works as expected.