How to find the user record in user table with sys ID in Script Include from sysID retrieved from UI Action and retrieve other field values from User table

Sushma Uday C
Tera Contributor

We have Contact field, we are getting contact details from the form in UI action and passing the sys ID to script include, but not able to find same record on user table and retrieve the other field for the same record from user table.

Not sure what's going wrong in below script. Please below script include and UI action 

find_real_file.png

find_real_file.png

Thanks in Advance

18 REPLIES 18

shloke04
Kilo Patron

Hi,

I cannot see in your screenshot on what are you trying to retrurn from your Script Include. Can you post the entire script include code here for the function which you are calling in your UI Action i.e. "setDetails" to help you further.

I don't see an issue till now in your code until you post the entire thing here.

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hi,

 

we are trying get the variables and add them to the URL the is being build in this script.

PFB script.

 

var CareARforFSMWorkspace = Class.create();
CareARforFSMWorkspace.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
setDetails: function(){

var my_sysID = this.getParameter('sysparm_sysID');
var my_table = this.getParameter('sysparm_table');
var my_contact_sysID = this.getParameter('sysparm_contact_sysID');
var baseURL = gs.getProperty('x_care3_carear_fsm.web.base.url');

var fqdn = gs.getProperty('instance_name') + '.service-now.com';
var currentUser = gs.getUser();
var userName = currentUser.getDisplayName();
var userRole = currentUser.getUserRoles()[0];

var gr1 = new GlideRecord('sys_user');
gr1.addQuery('sys_id', my_contact_sysID);
gs.info("contactsysID" +my_contact_sysID);
gr1.query();

if(gr1.next()){
gs.info("contactsysID1" +my_contact_sysID);
var contactNo = gr1.getValue('phone');
gs.info("contact" +contactNo);
}


var gr= new GlideRecord(my_table);
if(!gr.isValid()){
return;
}
gr.get(my_sysID);
if(!gr.canRead()){
return;
}
var numberWO = gr.getDisplayValue('number');

//build answer (URL)
var careARURL = baseURL+'?serviceNow=true&id='+numberWO+'&name='+userName+'&table_name='+my_table+'&table_sys_id='+my_sysID+ contact +'&fqdn='+fqdn+'&origin=https://' +fqdn+ '/now/workspace/agent/record/' +my_table+ '/' +my_sysID + '&file_name=true';

return careARURL;
},

type: 'CareARforFSMWorkspace'
});

 

 

Couple of things in your Script Include here:

Can you comment out the below line of code in your Script Include:

var userRole = currentUser.getUserRoles()[0];

I see you are not using this variable userRole anywhere in your Script Include and also it is not the correct way to check for User Roles. It will not give you an valid Output.

Also the URL which you are trying to return is not proper as you have mention contact in the line number 38 which you have not defined.

I have modified the Script Include, try this and let me know how you are going on this;

var CareARforFSMWorkspace = Class.create();
CareARforFSMWorkspace.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    setDetails: function() {

        var my_sysID = this.getParameter('sysparm_sysID');
        var my_table = this.getParameter('sysparm_table');
        var my_contact_sysID = this.getParameter('sysparm_contact_sysID');
        var baseURL = gs.getProperty('x_care3_carear_fsm.web.base.url');

        var fqdn = gs.getProperty('instance_name') + '.service-now.com';
        var currentUser = gs.getUser();
        var userName = currentUser.getDisplayName();
        

        var gr1 = new GlideRecord('sys_user');
        gr1.addQuery('sys_id', my_contact_sysID);
        gs.info("contactsysID" + my_contact_sysID);
        gr1.query();

        if (gr1.next()) {
            gs.info("contactsysID1" + my_contact_sysID);
            var contactNo = gr1.getValue('phone');
            gs.info("contact" + contactNo);
        }


        var gr = new GlideRecord(my_table);
        if (!gr.isValid()) {
            return;
        }
        gr.get(my_sysID);
        if (!gr.canRead()) {
            return;
        }
        var numberWO = gr.getDisplayValue('number');

        //build answer (URL)
        var careARURL = baseURL + '?serviceNow=true&id=' + numberWO + '&name=' + userName + '&table_name=' + my_table + '&table_sys_id=' + my_sysID + '&contact=' + contactNo + '&fqdn=' + fqdn + '&origin=https://' + fqdn + '/now/workspace/agent/record/' + my_table + '/' + my_sysID + '&file_name=true';

        return careARURL;
    },

    type: 'CareARforFSMWorkspace'
});

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

For reference URL which you was returning had a unknow text named "contact" which is not defined anywhere in your script include, highlighting it in Red below:

find_real_file.png

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hey,

That was name I earlier used but now I changed it correct, Even though I change it thats it not what the issue I think.

I am not able to query the sys_use table with sys ID in script include which I am getting from UI action. Its not even returning any thing after the query  just the script is being terminated after this "gr1.addQuery('sys_id', my_contact_sysID);".