using GlideAjax to update Change Request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 07:36 AM
Hello, can you help me why this simple script include doesn't work?
Name: FIG_update_comments
Application: Global
Accesible from: All application scopes
Script:
var ga = new GlideAjax('FIG_update_comments');
ga.addParam('sysparm_name', 'upd');
ga.getXML(mycallback);
function mycallback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 09:48 AM
what you are expecting from this?
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 12:38 PM
I'm just learning GlideAjax with this script. The goal would be to replace all GlideRecords in the Client Scripts with GlideAjax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 12:49 PM
I think you're misunderstanding the reason for using a Script Includes. You're meant to send it Client-side data in order to perform an action (assumption is a query) on the Server-side, which then provides you a value or values back to use Client-side.
You gain the efficiencies of doing something Server-side via Client.
What you've got written there is just a straight-up record update, which should be handled in a Business Rule instead.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 12:51 PM
I would suggest here first try to print some logs in script include and add alert() in client script to check if your script include executed successfully or not ?
eg:
Script:
var FIG_update_comments = Class.create();
FIG_update_comments.prototype = Object.extendsObject(AbstractAjaxProcessor, {
upd: function() {
var chg = new GlideRecord('change_request');
chg.addQuery('number', 'CHG0033796');
chg.query();
gs.log('Row Count is '+ chg.getRowCount());
if (chg.next()) {
chg.comments = 'Updated!';
chg.update();
return 'updated';
}
},
type: 'FIG_update_comments'
});
Client Script:
onLoad Client Script script:
var ga = new GlideAjax('FIG_update_comments');
ga.addParam('sysparm_name', 'upd');
ga.getXML(mycallback);
function mycallback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert('Getting Result '+ answer );
}
Give a try and see if you are getting any response in logs and alert.
Thanks,
Harsh