Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.
To perform the actions here, you should have a basic understanding of JavaScript, and/or jQuery. Also, you should have basic knowledge of accessing form elements.
To add your custom script for the new UI
Write the following code in the Reusable Script Functions section:
function validateName() {
var form = _sdForm;
var name = getTextFieldValue(form, ‘user_name’); // prefer to use JavaScript Platform API or you can do it through fieldname directly (Ex. _sdForm.user_name.value).
var regex = new RegExp(/^[A-Za-z\s]+$/);
if (regex.test(name)) {
return true;
} else {
// Alert user with validation message.
alert(‘Name should contain only letter and space!’);
// Cancel the SAVE action of the form by returning false.
return false;
}
Write the following code in On Save Script section:
return validateName();
We recommend you to access the field through JavaScript Platform API. However, we do not restrict you from using it.
Note: Here, we declare the method validateName() in the Reusable Script Functions tab and call it in the On Save Script tab. You can also declare the method in On Save Script tab and then call it. Or, you can write only the method body in the On Save Script Tab. This requires no method declaration and calls.