Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Display VIP group in SOW

Jay80
Tera Contributor

Hi,

 

we have VIP groups, we need to show the VIP group name beside the requested for user in SOW when creating an Incident is it possible? if so how? we have similar set up for Native UI, i have attached the screenshot for same

3 REPLIES 3

G Ponsekar
Tera Guru

Hi @Jay80 ,

 

Can you try with placeholder to display VIP group name beside Requested for field?

Create client callable Script include and client script to achieve this

Script Include: VIPGroupInfo

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

    getVIPGroupNames: function() {
        var userId = this.getParameter('sysparm_user_id');
        var groupNames = [];

        if (JSUtil.nil(userId)) {
            return '';
        }

        var grMember = new GlideRecord('sys_user_grmember');
        grMember.addQuery('user', userId);
        grMember.query();

        while (grMember.next()) {
            // Assuming VIP groups contain 'VIP' in their name
            if (grMember.group.name.indexOf('VIP') > -1) {
                groupNames.push(grMember.group.name.toString());
            }
        }
        return groupNames.join(', ');
    },

    type: 'VIPGroupInfo'});

Client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        // When the field is cleared, reset the placeholder        g_form.setFieldPlaceholder('requested_for', '');
        return;
    }

    // Check if the user is VIP. The VIP status is already on the user record.
    var isVIP = g_form.getReference('requested_for').vip;

    if (isVIP) {
        // Make a GlideAjax call to the Script Include
        var ga = new GlideAjax('VIPGroupInfo');
        ga.addParam('sysparm_name', 'getVIPGroupNames');
        ga.addParam('sysparm_user_id', newValue);
        ga.getXMLAnswer(function(answer) {
            if (answer) {
                var newPlaceholder = 'VIP Group(s): ' + answer;
                g_form.setFieldPlaceholder('requested_for', newPlaceholder);
            }
        });
    } else {
        // If the user is not VIP, clear any VIP-related placeholder        g_form.setFieldPlaceholder('requested_for', '');
    }
}

 

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

 

Jay80
Tera Contributor

hello @G Ponsekar thanks for the reply, surely will check if this works and update you.

 

Thanks.

Ankur Bawiskar
Tera Patron
Tera Patron

@Jay80 

you can use field decorator for this

UI Builder Deep Dives: Field Action Decorator 

Add a field decorator action button 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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