GlideRecord is not a constructor Error

Stephan S_
Tera Expert

Hi Community,

i have a little UI-Action, wich exports my Cases and sets them from one state to another.

As I am moving to Orlando, my UI-Action does not work anymore and I have no clue why. Can you please help out?

The Error:

find_real_file.png

 

The Code:

function downloadExcel(){
var checked = g_list.getChecked(); // get's the sys_id of the checked records
var query = "sys_idIN" + checked.toString();
var rows = checked.split(",").length; // rows to be sent to the export function
// this code you can move to script include and go GlideAjax as well
var gr = new GlideRecord('x_bhhgh_his_cases_his_cases');
gr.addQuery('sys_id', 'IN', checked);
gr.query();
while(gr.next()){
gr.state = 6;
gr.update();
}
var view = "Workspace"; // set this to default for columns present in default view for list layout
// set this to empty if you want all the columns present in the list layout including the customized ones.
var dialog = new GwtPollDialog('x_bhhgh_his_cases_his_cases', query, rows, view, 'unload_excel_xlsx');
dialog.execute();
}

Commenting out Line 6 to 11 (the part where the State gets modyfied) everthing runs properly...

 

Thanks a lot in advance!!!

Best Regards,

Stephan

 

1 ACCEPTED SOLUTION

Hi Stephan,

So you should be calling like this

I have added toString() as well while sending the checked values

Please try

var ga = new GlideAjax('x_bhhgh_his_cases.updateRecords');
    ga.addParam('sysparm_name', 'updateRecorWithValue');
    ga.addParam('sysparm_checked', checked.toString());
    ga.getXML(processResponse);
    
    function processResponse(response) {
    var result = response.responseXML.documentElement.getAttribute("answer");
    }

Also did you verify row count in script include?

Try adding some logs to function

updateRecorWithValue: function(){

        var checked = this.getParameter('sysparm_checked');

        gs.info('sys_ids are ' + checked);
        var gr = new GlideRecord('x_bhhgh_his_cases_his_cases');
        gr.addQuery('sys_id', 'IN', checked);
        gr.query();

        gs.info('Row count is: ' + gr.getRowCount());
        while(gr.next()){

        gs.info('Inside while');
            gr.state = 6;
            gr.update();
        }
    },

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

15 REPLIES 15

asifnoor
Kilo Patron

Hello Stephan,

GlideRecord is basically a server side code. You have to call Si and keep this code inside SI. You should not use this in client script.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Stephan,

It seems your UI action code is in custom scope "x_bhhgh"

so GlideRecord in client side is not allowed in scoped application.

you can perform GlideAjax to update the state for those records selected as below

UI Action:

function downloadExcel(){
var checked = g_list.getChecked(); // get's the sys_id of the checked records
var query = "sys_idIN" + checked.toString();
var rows = checked.split(",").length; // rows to be sent to the export function
// this code you can move to script include and go GlideAjax as well

 var ga = new GlideAjax('updateRecords');
    ga.addParam('sysparm_name', 'updateRecorWithValue');
    ga.addParam('sysparm_checked', checked);
    ga.getXML(processResponse);
    
    function processResponse(response) {
    var result = response.responseXML.documentElement.getAttribute("answer");
    }

var view = "Workspace"; // set this to default for columns present in default view for list layout
// set this to empty if you want all the columns present in the list layout including the customized ones.
var dialog = new GwtPollDialog('x_bhhgh_his_cases_his_cases', query, rows, view, 'unload_excel_xlsx');
dialog.execute();
}

Script Include: It should be client callable; ensure it is in your custom scope

var updateRecords = Class.create();
updateRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	updateRecorWithValue: function(){

		var checked = this.getParameter('sysparm_checked');
		var gr = new GlideRecord('x_bhhgh_his_cases_his_cases');
		gr.addQuery('sys_id', 'IN', checked);
		gr.query();
		while(gr.next()){
			gr.state = 6;
			gr.update();
		}
	},

	type: 'updateRecords'
});

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

i tryed your code - The dialog opens and downloads. But the State gets not updated. Also I see no Error-Message 😞

Do you have any more clues?

 

Thanks!

Hi Stephan,

can you check script include is client callable?

please share your script include screenshot

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader