The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to look for field name in a client script

DevtoSME
Giga Guru

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.

 

3 REPLIES 3

Bert_c1
Kilo Patron

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.

Community Alums
Not applicable

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

Bert_c1
Kilo Patron

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.