- 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-23-2014 09:54 PM
Experts please share your input...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2014 06:51 AM
Hi,
Unfortunately,you have to write two client each on every field to run the same.There is no such way, as per my thinking.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2014 07:21 AM
g_form has a couple of undocumented things that should allow you to do this:
- g_form.modified : Boolean True/False
- g_form.modifiedFields : Object
- g_form.modifiedFields could contain something like:
- incident.caller_id: true
- You can access g_form from anywhere on the Client-side.
- Bear in mind this undocumented functionality so it might change in a future release
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-25-2014 11:02 AM
Dear Andrew,
Thank you for your input but I am not getting how and where to start my script. I have to write a script on KB form (kb_knowledge) and should execute when either field A or field B on the form changes.
If I go with onChange client script then I am not able to satisfy above said condition of either field A or field B on the form changes. Since, both of these fields will be used in my GlideAjax call therefore, I do not opt writing two onChange client scripts.
Can you please suggest?
Brgds, AM