- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 09:24 AM
So i have a requested item field in test and dev with different field names and to do a workaround i need to make an array to include both fields.
im trying to get this to work but no progress. with out the array the client scripts works fine for the 'requested_for" field in dev (field in test is 'request') but i need to account for the 'request' field in test. now this this code wont produce a field message for dev at all
any help is appreciated
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Define an array of field names to check against
var fieldNames = ['requested_for', 'request'];
// Check if the control's name is in the array of field names
if (!fieldNames.includes(control.name)) {
return;
}
// Check if the new value is empty
if (newValue === '') {
g_form.hideFieldMsg(control.name); // Clear any existing message if new value is empty
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;
// Determine message based on user's grade of service
if (userGradesOfService == "elite") {
g_form.showFieldMsg(control.name, 'This user is Elite', 'error');
} else {
g_form.hideFieldMsg(control.name);
}
} else {
// Handle case where reference could not be fetched
console.log('Failed to get reference for', control.name);
g_form.hideFieldMsg(control.name); // Clear any existing message if reference fetch fails
}
});
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-18-2024 12:17 PM
Hi @DevtoSME ,
There are some issues in you script.
Please find the updated script-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Define an array of field names to check against
var fieldNames = ['requested_for', 'request'];
// Check if the control's name is in the array of field names
if (!fieldNames.includes(control.name)) {
return;
}
// Check if the new value is empty
if (newValue === '') {
g_form.hideFieldMsg(control.name); // Clear any existing message if new value is empty
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;
// Determine message based on user's grade of service
if (userGradesOfService == "elite") {
g_form.showFieldMsg(control.name, 'This user is Elite', 'error');
} else {
g_form.hideFieldMsg(control.name);
}
} else {
// Handle case where reference could not be fetched
console.log('Failed to get reference for', control.name);
g_form.hideFieldMsg(control.name); // Clear any existing message if reference fetch fails
}
});
}
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 12:17 PM
Hi @DevtoSME ,
There are some issues in you script.
Please find the updated script-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Define an array of field names to check against
var fieldNames = ['requested_for', 'request'];
// Check if the control's name is in the array of field names
if (!fieldNames.includes(control.name)) {
return;
}
// Check if the new value is empty
if (newValue === '') {
g_form.hideFieldMsg(control.name); // Clear any existing message if new value is empty
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;
// Determine message based on user's grade of service
if (userGradesOfService == "elite") {
g_form.showFieldMsg(control.name, 'This user is Elite', 'error');
} else {
g_form.hideFieldMsg(control.name);
}
} else {
// Handle case where reference could not be fetched
console.log('Failed to get reference for', control.name);
g_form.hideFieldMsg(control.name); // Clear any existing message if reference fetch fails
}
});
}
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