How to look for field name in a client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 11:16 AM - edited 06-18-2024 11:21 AM
Im trying to write an array to include two field names for the requested items table.
do i use the control object or how do i write this into my script. my original client script works but the field is different in another environment. please help. still on my coding journey so any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 12:05 PM
Hi Joyea,
I tried in my PDI and used:
var fieldNames = ['incident.requested_for', 'incident.severity'];
as my client script is defined on the incident table. Seems 'control' is table_name.field_name.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 12:05 PM
Hi @DevtoSME ,
Here is an updated script-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// The array of field names to check
var fieldNames = ['requested_for', 'request'];
// Check if the control's name is one of the field names
if (fieldNames.includes(control.name)) {
// Check if the new value is empty
if (newValue === '') {
g_form.hideFieldMsg(control.name);
return;
}
// Get the caller's reference
g_form.getReference(control.name, function(userGR) {
if (userGR) {
// Access the user's grade of service
var userGradesOfService = userGR.u_grade_of_service;
if (userGradesOfService == "elite") {
g_form.showFieldMsg(control.name, 'This user is Elite', 'error');
} else {
g_form.hideFieldMsg(control.name);
}
}
});
}
}
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 01:19 PM - edited 06-18-2024 03:33 PM
I suggest add
alert('control.name = ' + control.name);
as the first line in your client script, and test.
And why are you checking for field name in the code? onChange client scripts use a table and field name.