default text in Description field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 09:20 PM
Hi Team
when ever user selects ' Request category is ' remove ser access '. below text has to populate in description field .
How to achieve this in onchange cilent script .
NOTE - Description field where calling from Variable set .
Text :-
Exmaple text is required .
Please priovde sciript .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 09:23 PM
To achieve this using an onchange client script in ServiceNow, you can write a script that listens to changes in the 'Request Category' variable and updates the 'Description' field accordingly.
Below is the code:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (newValue == 'remove_user_access') { // validate the field name
// Get a reference to the 'Description' field
var descriptionField = g_form.getControl('description');
// Set the desired text in the 'Description' field
descriptionField.value = 'Example text is required.';
}
}
Kindly mark helpful/accepted if it helps you.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 09:30 PM
Test reults :
If change to anyother options also , Default text is remains same .
How to fix this ,
When ever i select ' remove user access ' then only , it has to be show ? not for all options
@Maddysunil please help me here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 09:34 PM
Please add else condition in your same script in the last
else {
descriptionField.value = '';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2024 09:37 PM - edited 02-15-2024 09:40 PM
Modify the like below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Check if the 'Request Category' variable has changed to 'remove_user_access'
if (newValue == 'remove_user_access') {
// Get a reference to the 'Description' field
var descriptionField = g_form.getControl('description');
// Set the desired text in the 'Description' field
descriptionField.value = 'Example text is required.';
} else {
// For other options, reset the 'Description' field to its default value
var descriptionField = g_form.getControl('description');
descriptionField.value = ''; // You may need to set the default value based on your requirements
}
}
Kindly mark helpful/accepted if it helps you.
Thanks