- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-23-2014 06:54 AM
We can use onChange client script to check if any one of available fields on the form changes. I need to write an client script for two form fields, I mean script should run if any one of them changes.How can we achieve it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2014 04:11 AM
As abhishekte suggests, you will need two client scripts on kb_knowledge, but you can use a third to put your key code in one place:
Name: FieldA Change
Active: Checked
Global: Checked
Type: onChange
Table: Knowledge [kb_knowledge]
Field name: FieldA
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
kbMyFunction();
}
Name: FieldB Change
Active: Checked
Global: Checked
Type: onChange
Table: Knowledge [kb_knowledge]
Field name: FieldB
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
kbMyFunction();
}
Then you need to define the shared function that both scripts will call, so create a third new Client Script:
Name: kbMyFunction
Active: Checked
Global: Checked
Type: onLoad
Table: Knowledge [kb_knowledge]
Script:
function onLoad() {
// do nothing
}
function kbMyFunction() {
var fielda = g_form.getvalue('u_fielda');
var fieldb = g_form.getvalue('u_fieldb');
if (fielda != '' && fieldb != '') {
alert('Sending GlideAjax');
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name','helloWorld');
ga.addParam('sysparm_u_fielda',fielda);
ga.addParam('sysparm_u_fieldb',fieldb);
ga.getXML(HelloWorldParse);
}
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
See GlideAjax - ServiceNow Wiki for how to use GlideAjax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-26-2014 04:11 AM
As abhishekte suggests, you will need two client scripts on kb_knowledge, but you can use a third to put your key code in one place:
Name: FieldA Change
Active: Checked
Global: Checked
Type: onChange
Table: Knowledge [kb_knowledge]
Field name: FieldA
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
kbMyFunction();
}
Name: FieldB Change
Active: Checked
Global: Checked
Type: onChange
Table: Knowledge [kb_knowledge]
Field name: FieldB
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
kbMyFunction();
}
Then you need to define the shared function that both scripts will call, so create a third new Client Script:
Name: kbMyFunction
Active: Checked
Global: Checked
Type: onLoad
Table: Knowledge [kb_knowledge]
Script:
function onLoad() {
// do nothing
}
function kbMyFunction() {
var fielda = g_form.getvalue('u_fielda');
var fieldb = g_form.getvalue('u_fieldb');
if (fielda != '' && fieldb != '') {
alert('Sending GlideAjax');
var ga = new GlideAjax('HelloWorld');
ga.addParam('sysparm_name','helloWorld');
ga.addParam('sysparm_u_fielda',fielda);
ga.addParam('sysparm_u_fieldb',fieldb);
ga.getXML(HelloWorldParse);
}
}
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
See GlideAjax - ServiceNow Wiki for how to use GlideAjax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2014 05:27 AM
Dear Andrew & Abhishek,
Thank you for sharing your input and expertise. I am done with my requirement and it works
Brgds, AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-09-2016 05:17 PM