using GlideAjax to update Change Request

DoDo labs___
Mega Sage

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 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();
        if (chg.next())
            {
                chg.comments = 'Updated!';
                chg.update();
                gs.addInfoMessage('Updated!');
            }
 
    },
 
    type: 'FIG_update_comments'
});
 
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");
}

 

 

7 REPLIES 7

Saurabh Gupta
Kilo Patron
Kilo Patron

what you are expecting from this?


Thanks and Regards,

Saurabh Gupta

I'm just learning GlideAjax with this script. The goal would be to replace all GlideRecords in the Client Scripts with GlideAjax.

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.

Harsh Vardhan
Giga Patron

Hi @DoDo labs___  

 

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