client script on a string field on a user table in not working on same field in service portal view

showmiro1
Tera Contributor

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.

 

showmiro1_0-1710965293400.png

The above picture is the user table field and this field only accept numeric only.

showmiro1_1-1710965379107.png

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?

1 ACCEPTED SOLUTION

@showmiro1 

 

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 :

 

AmitVerma_0-1711083159999.png

 

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

 

AmitVerma_2-1711083307587.png

 

 

AmitVerma_1-1711083265804.png

 

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.

View solution in original post

8 REPLIES 8

@showmiro1 

 

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.

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

showmiro1_0-1711027001185.png

 

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.

showmiro1_2-1711027106627.png

3. Tried saving record on the same service portal view in the backend and the client script works.

showmiro1_3-1711027161115.png

 

4. Goto service portal and click on your profile page at the upper right.

showmiro1_1-1711027057197.png

 



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.

showmiro1_4-1711027203565.png

 

6. Here is the view after saving on service portal

showmiro1_5-1711027604560.png

 

@showmiro1 

 

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 :

 

AmitVerma_0-1711083159999.png

 

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

 

AmitVerma_2-1711083307587.png

 

 

AmitVerma_1-1711083265804.png

 

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.

Thank you. This works as expected.