Make Users available based on Catalog Item - Variable value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 10:17 AM
Hi all,
I have a requirement in Catalog Item - Which contains variable - Domain which is a radio button - contains data1, data2, data3, data4
In Catalog Item - It also contains MRV which has User - Reference filed
If data1 is selected than in Catalog Item than in MRV User filed only users should only available which contains email ends with @data1.com, other users should not be available similarly for data2 - @data2.com, data3 - @data3.com, data4 - @data4.com Please explain in detail with the code(Script include) and How I need to call the Script include in the User filed in MRV Advanced qualifier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2024 01:38 PM
Hi @Mahesho11 ,
Create a multichoice field as below,
and create a reference field Users and in advanced reference qualifier add the below code,
javascript: new FitlerEmailIdOfUser().getName(current.variables.testing_data);
Script include:
var FitlerEmailIdOfUser = Class.create();
FitlerEmailIdOfUser.prototype = {
initialize: function() {},
getName: function(data) {
gs.info('Data' + data);
var arr =[];
var ga = new GlideRecord('sys_user');
if (data == 'data1') {
ga.addEncodedQuery('emailENDSWITH@example.com'); // Change The query accordingly
} else if (data == 'data2') {
ga.addEncodedQuery('emailENDSWITH@data4.com'); // Change The query accordingly
}
else if(data == 'data3'){
ga.addEncodedQuery('emailENDSWITH@data4.com'); // Change The query accordingly
}
ga.query();
while(ga.next()){
arr.push(ga.getValue('sys_id'));
}
gs.info('arr' + arr);
return 'sys_idIN'+ arr;
},
type: 'FitlerEmailIdOfUser'
};
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2024 08:12 AM
This is working for Catalog Item inside data type and User field but my requirement is to connect Based on data field to connect with MRV User Filed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2024 05:27 AM
Hi @Mahesho11 ,
If that is the case then add the advanced reference qualifier in the variable inside variable set, but send one more value which is catalog item sys_id so that in the script include you can check the catalog item and if it is your item then only check for the data field else it would return all the records which are active.
reference qualifier:
javascript: new FitlerEmailIdOfUser().getName(current.variables.testing_data,current.cat_item);
script include:
var FitlerEmailIdOfUser = Class.create();
FitlerEmailIdOfUser.prototype = {
initialize: function() {},
getName: function(data, uniqueId) {
// gs.info('Data ' + data);
// gs.info('UniqueID ' + uniqueId);
var arr = [];
var ga = new GlideRecord('sys_user');
if (uniqueId == '6ea35bdcc3310210baba7405e401316a') //check for your catalog item
{
// gs.info('Inside if');
if (data == 'data1') {
ga.addEncodedQuery('emailENDSWITH@example.com'); // Change The query accordingly
} else if (data == 'data2') {
ga.addEncodedQuery('emailENDSWITH@data4.com'); // Change The query accordingly
} else if (data == 'data3') {
ga.addEncodedQuery('emailENDSWITH@data4.com'); // Change The query accordingly
}
} else {
ga.addQuery('active', 'true');
}
ga.query();
while (ga.next()) {
arr.push(ga.getValue('sys_id'));
}
gs.info('arr' + arr);
return 'sys_idIN' + arr;
},
type: 'FitlerEmailIdOfUser'
};
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang