com.glide.script.RhinoEcmaError: Cannot find function getRecord in object com.glide.script.fencing.ScopedUser

hanaphouse
Giga Guru

I am getting this error when running this line of code in the Customer Service application. What could be other option to do query users attributes such as phone, email, etc?

Error:

com.glide.script.RhinoEcmaError: Cannot find function getRecord in object com.glide.script.fencing.ScopedUser

Code:

userPhone = gs.getUser().getRecord().getValue('phone');
1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi hanaphouse,

It's necessary to use GlideAjax to call Script Include on the server to query a table.

Example of client script calling script include to set phone number to field named "phone"

Client Script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ajax = new GlideAjax('GetUserInfo');
    ajax.addParam('sysparm_name', 'getUserPhone');
    ajax.addParam('sysparm_user_id', newValue);
    ajax.getXMLAnswer(function(answer) {
        if (answer.length > 0) {
            g_form.setValue('phone', answer);
        }
    });
}

Script Include

var GetUserInfo = Class.create();
GetUserInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserNameAndEmpNo: function() {
        var user_id = this.getParameter('sysparm_user_id');
        var grUser = new GlideRecord('sys_user');
        if (grUser.get(user_id)) {
            return grUser.phone.toString;
        }
    },
    type: 'GetUserInfo'
});

View solution in original post

3 REPLIES 3

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi hanaphouse,

It's necessary to use GlideAjax to call Script Include on the server to query a table.

Example of client script calling script include to set phone number to field named "phone"

Client Script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ajax = new GlideAjax('GetUserInfo');
    ajax.addParam('sysparm_name', 'getUserPhone');
    ajax.addParam('sysparm_user_id', newValue);
    ajax.getXMLAnswer(function(answer) {
        if (answer.length > 0) {
            g_form.setValue('phone', answer);
        }
    });
}

Script Include

var GetUserInfo = Class.create();
GetUserInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserNameAndEmpNo: function() {
        var user_id = this.getParameter('sysparm_user_id');
        var grUser = new GlideRecord('sys_user');
        if (grUser.get(user_id)) {
            return grUser.phone.toString;
        }
    },
    type: 'GetUserInfo'
});

johnabbott
Tera Contributor

Hi,

I am writing a query business rule (so it is server side) on the Business Capability table, which is in the Application Portfolio Management application scope, and therefore uses 'GlideUser - Scoped' in the following statement:

var d = gs.getUser().getDomainID();

I am getting the following error:

com.glide.script.RhinoEcmaError: Cannot find function getDomainID in object com.glide.script.fencing.ScopedUser@c52892.

the getDomainID method is in the documentation for the scoped API, though it is absent from the global version.

As this is server side, clearly GlideAjax is irrelevant in this context. 

So, am I doing something wrong or is there a defect in GlideUser?

I shall be grateful for any advice.

Cheers,

John

I faced a very similar issue but in my case I was able to resolve since my script include was extending another one but it turns out the "parent" or main one was inactive. After I changed it to active then the error went away. I know this way too late but I hope it helps someone else.