Script Include

P1234
Tera Contributor

I need to print 10 users Manager , Location , Email , Department , Mobile Number using Server side to client side using Script Include.

 

I know the code but at a time to print 10 or 20 users related Manager , Location , Email , Department , Mobile Number.

 

Any idea please let me know.

4 REPLIES 4

Cheikh Ahmadou
Tera Guru

Try to store them as an array of object, and return it from the script include before trying to print.

Robert H
Mega Sage

Hello @P1234 ,

 

Please provide more details about the requirement.

I guess you don't need 10 random users. Are the users referenced in some field on a record?

And do you need to print the information when the form of the record loads, or when something happens (e.g. field gets updated)?

 

Regards,

Robert

P1234
Tera Contributor

Hi Robert,

 

For example 10 users like

 

User Name:

1.Abel Tuter : Manager , location , Department , Mobile number , email

2.Abraham Lincoln : Manager , location , Department , Mobile number , email

3.Adela Cervantsz : Manager , location , Department , Mobile number , email

4.Andrew Och : Manager , location , Department , Mobile number , email

5. Amos Linnan : Manager , location , Department , Mobile number , email

6.Chi Greenlaw : Manager , location , Department , Mobile number , email

7.Corinne Cowan : Manager , location , Department , Mobile number , email

8.Deepa Shah : Manager , location , Department , Mobile number , email

9.Dionne Borycz : Manager , location , Department , Mobile number , email

10.Hillary Holmes : Manager , location , Department , Mobile number , email

 

need to print any 10 or 20 users related date at time using script include.

 

I know how to print one user related data.

 

 

 

 

Hello @P1234 ,

 

Yeah, I got it that you need to print 10 users and that kind of information.

But where are these users specified? Are they really random? That would not be a realistic requirement.

What is the use case and actual requirement you were given?

 

Anyway, taking your statements literally, here is a solution that does this:

 

Script Include (make sure that GlideAjax Enabled checkbox is selected) :

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

    get: function() {
        var grUser = new GlideRecord('sys_user');
        grUser.setLimit(10);
		grUser.orderBy('name');
        grUser.query();

        var answer = [];
        while (grUser.next()) {
            answer.push(gs.getMessage('{0}: {1}, {2}, {3}, {4}, {5}', [
                grUser.getDisplayValue('name'),
                grUser.getDisplayValue('manager'),
                grUser.getDisplayValue('location'),
                grUser.getDisplayValue('department'),
                grUser.getDisplayValue('mobile_phone'),
                grUser.getDisplayValue('email')
            ]));
        }
        return JSON.stringify(answer);
    },

    type: 'TenRandomUsers'
});

 

Client Script (I used onLoad since you did not give specifics):

function onLoad() {
    var ga = new GlideAjax('TenRandomUsers');
    ga.addParam('sysparm_name', 'get');
    ga.getXMLAnswer(response => {
        var users = JSON.parse(response);
        g_form.addInfoMessage('Here are 10 random users:<br>' + users.join('<br>'));
    });
}

 

Result:

RobertH_0-1748263405020.png

 

Regards,

Robert