- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 04:07 AM
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:
Please help
Regards,
Lucky
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 04:34 AM - edited 05-19-2024 12:15 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 04:19 AM
Hi,
If you want to display the value of the cmdb_ci field please try
alert(g_form.getValue('cmdb_ci'));
Regards,
Karthik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 04:34 AM - edited 05-19-2024 12:15 PM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 07:18 AM - edited 05-20-2024 07:28 AM
Hello Robbie,
Thanks a lot. It's working
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 07:24 AM
Hi @Lucky1,
Can you remove the brackets at the end of the string 'value' as shown below.
It should end with .value;
It should not end with .value()
It's a subtle difference but make the difference. See my screen shot and initial response again.
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