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

Amit Verma
Kilo Patron
Kilo Patron

Hi @showmiro1 

 

Is the Global Checkbox checked for your client script ? If not, please check it and retry.

 

AmitVerma_0-1710994982871.png

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

shyamkumar VK
Kilo Patron

@showmiro1 , Check If your current Client script is designed for any Particular view , If this is not on any Specific check Global is Checked on Client script

 

Also if your checking this on any Portal , UI type should be Set to ‘ALL’

 

Check this settings and let me know if still see any Issue

 

Regards,

Shyamkumar

 

 

Please mark this as helpful and accept as a solution if this resolves your Ask.
Regards,

Shyamkumar

ramprasadk
Tera Contributor

May be script logic not supporting in Portal. Please share script logic

showmiro1
Tera Contributor

@Amit Verma The Global checkbox is checked
@shyamkumar VK  UI is set to ALL

@ramprasadk Below is the script logic on the field


function onSubmit() {
   //Type appropriate comment here, and begin script below
   // Get the value of the 'u_pin_id' field
    var pinId = g_form.getValue('u_pin_id');
   
    if(!pinId){
        return true;
    }

    // Check if the value is not exactly 5 characters
    if (pinId.length !== 5 || isNumber(pinId) == false) {
        // Display an alert message
        g_form.addErrorMessage('Pin ID must be 5 numeric numbers.');

        // Prevent the form submission
        return false;
    }

    // Allow the form submission if the validation passes
    return true;
}