How to get the sysids of users added in also request for variable in Catalog item

supriya pratapa
Tera Guru

In the catalog item, we have requested for variable under which we can enable also request for. The also request for enables in raising request for multiple requestors. I have a requirement to abort submitting the request even if one of the requestor's locations is out of India. How can this be achieved. 

1 ACCEPTED SOLUTION

@supriya pratapa 

Hope you are doing good.

Did my reply answer your question?

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

View solution in original post

7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @supriya pratapa 

I’m not sure what the backend of your use case is, but if the request location is not India, it will be considered as another route or location outside of India. However, make sure all required location data is updated in the user table.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron
Tera Patron

@supriya pratapa 

is requestor a list collector variable reference to sys_user?

If yes then why not restrict the users itself by adding reference qualifier

javascript:'location.country!=India';

if not then you can use onChange + GlideAjax and then validate this

even if 1 user has location outside India then show error in field message

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var requestorIds = g_form.getValue('requestors'); // Assuming 'requestors' is the field with multiple requestors

    var ga = new GlideAjax('CheckRequestorLocation');
    ga.addParam('sysparm_name', 'checkLocations');
    ga.addParam('requestorIds', requestorIds);
    ga.getXMLAnswer(function(response) {
        if (response.toString() == 'true') {
            g_form.addErrorMessage('One or more requestors are located outside India.');
        } else {
            g_form.clearMessages();
        }
    });
}

Script Include: It should be client callable

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

    checkLocations: function() {
        var requestorIds = this.getParameter('requestorIds');
        var userGr = new GlideRecord('sys_user');
        userGr.addQuery('sys_id', 'IN', requestorIds);
        userGr.addQuery('location.country', 'India');
        userGr.setLimit(1);
        userGr.query();
        return userGr.hasNext();
    },

    type: 'CheckRequestorLocation'
});

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

Hi @Ankur Bawiskar 

Please find the attached screenshot. We have this requested for enabling multi requestors in OOB.

I want to fetch the sysids of users under Also request for field (in screenshot) and validate their location. 

@supriya pratapa 

why not restrict the users itself by adding reference qualifier, something like this

but please enhance

javascript:'location.country!=India';

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