How to convert my pseudo code into a working onLoad Client Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I have some pseudo code that I would like to use in a client script, but I'm not sure exactly how to convert it:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @SusanSchwar
What's the requirement here?
Here is code, make changes accordingly:
function onLoad() {
// Example condition: only when task = task1
if (g_form.getValue('task') !== 'task1') {
return;
}
// If name_of_field is true (checkbox / boolean)
if (g_form.getValue('name_of_field') === 'true') {
g_form.setReadOnly('name_of_field_2', false);
}
// If name_of_field_3 is currently read-only
if (g_form.isReadOnly('name_of_field_3')) {
g_form.setReadOnly('name_of_field_4', false);
}
}
Here is link to understand the above used functions better:
https://www.servicenow.com/docs/r/api-reference/c_GlideFormAPI.html
Regards,
Mohammed Zakir
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @SusanSchwar ,
Whats the use case here ?
function onLoad() {
// Get the current task number
var taskNumber = g_form.getValue('number');
if (taskNumber == 'TSK0010001') { // Replace with your specific task number
// Check if name_of_field is true
if (g_form.getValue('name_of_field') == 'true' || g_form.getValue('name_of_field') == true) {
g_form.setReadOnly('name_of_field_2', false);
}
// Check if name_of_field_3 is readonly and valid
if (g_form.getValue('name_of_field_3') != '') { // Checking if field has a value (is valid)
g_form.setReadOnly('name_of_field_4', false);
}
}
} *******************************************************************************************
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards,
