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

Can you confirm if you are using the right field in your UI Action i.e. "caller" which you are trying to pass from your UI Action.

Can you Right click on the caller field on your form and check what is the correct Field Name which you are passing.

Also put a log in your Script include and see what is coming in your script include afetr this line of code :

 var my_contact_sysID = this.getParameter('sysparm_contact_sysID');

gs.info('value coming from Ui Action '  + my_contact_sysID);

 

Regards,

Shloke

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

Regards,
Shloke

Hey,

 

I am referring to correct field and I am getting correct sysID as well in script Include from UI action i.e, Contact field.

First of all I would like to suggest is to build a structured code and not everything going within a single function which makes it really difficult to debug things.

I have modified and make it a structured format for you. Please use below:

Now I have put some logs in Line number 14 i.e.

 gs.info('Contact Number fetched from function is ' + contactNo);

Also in Line number 17 i.e.

gs.info('Number fetched is ' + getNum);

Can you show me with a screenshot of what are you getting in these logs. This way we can eliminate one after the other where the issue is.

Modified code for you:

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.getUserDisplayName();

        var contactNo = this._getUserDetails(my_contact_sysID);
        gs.info('Contact Number fetched from function is ' + contactNo);

        var getNum = this._getRecordNumber(my_table,my_sysID);
		gs.info('Number fetched is ' + getNum);

        //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;
    },

    _getUserDetails: function(userID) {
        gs.info('user ID passed ' + userID);
        var num;
        var gr1 = new GlideRecord('sys_user');
        gr1.addQuery('sys_id', userID);
        gr1.query();
        if (gr1.next()) {
            if (JSUtil.notNil(gr1.phone)) {
                num = gr1.phone.toString();
            } else {
                num = "Phone Number not present";
            }
        }
        return num.toString();
    },

    _getRecordNumber: function(my_table,my_sysID) {
        var gr = new GlideRecordSecure(my_table);
        gr.addQuery('sys_id',my_sysID);
        gr.query();
		if(gr.next()){
			return gr.number;
		}
      
    },


    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

Hey,

 

I tried it, PFB screenshot. User ID is passed but nothing is fetched 😞

 

find_real_file.png