On Change Client script error.

Lucky1
Tera Guru

Hi all,

 

I have created an On change Client script on Incident form, on the field 'Severity'.

I have just written alert(cmdb_ci');

 

So, on change of Severity field, it should show me alert. Right?

But it is showing error like below: 

Lucky1_0-1715944056130.png

 

 

Please help

 

 

Regards,

Lucky

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Lucky1,

 

There's a few things going on under the scenes that you may not be aware of.

 

First, to retrieve a field value in a Client script you need to leverage the g_form API such as g_form.getValue('field_name'). In addition, when you're trying to retrieve a reference field (which CI is), you need a further step as below - g_form.getDisplayBox('field_name').value - see below as to how to use this.

 

Use the below onChange Client Script.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.

 

Thanks, Robbie

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var ciDisplayVal = g_form.getDisplayBox('cmdb_ci').value;
    alert('Ci val: ' + ciDisplayVal);

}

 

 

 

 

 

Screenshot 2024-05-17 at 12.33.34.png

View solution in original post

5 REPLIES 5

maheshkhatal
Mega Sage

@Lucky1 , First of all you are missing a beginning single quote and also the proper way to get/alert the field name is 

g_form.getValue('field_name');

 

Mark my response helpful if it helped you.