- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 03:14 AM
Hi,
for our customer we have the requirment to filter catalog items based on the contact. When using the ootb 'Creat Request' button we are being redirecte to the swp portal in the workspace where the agent can see all active catalog items.
There is no way to filter the catalog items based on the contact on the customer case.
My idea was to create a ui actioin that opens a model that has the contact prefilled. A field that references to the catalog items. I have a script that returns all catalog item sys_id's the user has access to. I would like to use this to filter the catalog item reference field on the modal.
When the catalog item is selected, I would then want to re-use the code '
the modal should also load these params from the case
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 04:31 AM - edited 08-05-2024 06:05 AM
I've found a way to achieve this.
I've created a new ui action to open a modal. This modal show a catalog item choice field. The field is populated with the catalog items the contact or internal user has access to. With the g_service_catalog.openCatalogItem it opens the catalog item in a new tab on workspace.
Ui action
function onClick(g_form) {
var userId;
if(g_form.getValue('contact')){
userId = g_form.getValue('contact');
}
else if(g_form.getValue('internal_user')){
userId = g_form.getValue('internal_user');
}
var params = {};
params.sysparm_parent_table = "sn_customerservice_case";
params.sysparm_parent_sys_id = g_form.getUniqueValue();
var ga = new GlideAjax('global.CatalogUtilsAjax');
ga.addParam('sysparm_name', 'getCatalogItemsByUserId');
ga.addParam('sysparm_user_name', userId);
ga.getXMLAnswer(itemParse);
function itemParse(response) {
var itemChoice = JSON.parse(response);
var fields = [
{
type: 'choice',
name: 'selectItem',
label: getMessage('Select the catalog item you want to request'),
choices: itemChoice,
mandatory: true
},
];
g_modal.showFields({
title: 'Create Request',
fields: fields,
size: 'lg'
}).then(function(fieldValues) {
g_service_catalog.openCatalogItem('sc_cat_item', fieldValues.updatedFields[0].value, params);
});
}
}
GlideAjax
getCatalogItemsByUserId: function(){
var user_id = this.getParameter("sysparm_user_name");
var items = new global.CatalogUtils().getCatalogIdsByUserId(String(user_id));
return JSON.stringify(items);
},
Script include
getCatalogIdsByUserId: function(userId) {
//Get user's user criteria's
var getCriterias = new sn_uc.UserCriteriaLoader.getUserCriteria(userId, 'sc_cat_item_user_criteria_mtom');
var options = [];
//filter catalog items available for
var gr = new GlideRecord("sc_cat_item_user_criteria_mtom");
gr.addEncodedQuery('user_criteria.sys_idIN' + getCriterias + '^sc_cat_item.active=true');
gr.query();
while (gr.next()) {
if (gr.sc_cat_item.getDisplayValue())
options.push({
'value': String(gr.sc_cat_item.sys_id),
'displayValue': gr.sc_cat_item.getDisplayValue()
});
}
//sort display value alfabetical
options.sort(function(a, b) {
if (a.displayValue < b.displayValue) {
return -1;
}
if (a.displayValue > b.displayValue) {
return 1;
}
return 0;
});
return options;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2024 04:31 AM - edited 08-05-2024 06:05 AM
I've found a way to achieve this.
I've created a new ui action to open a modal. This modal show a catalog item choice field. The field is populated with the catalog items the contact or internal user has access to. With the g_service_catalog.openCatalogItem it opens the catalog item in a new tab on workspace.
Ui action
function onClick(g_form) {
var userId;
if(g_form.getValue('contact')){
userId = g_form.getValue('contact');
}
else if(g_form.getValue('internal_user')){
userId = g_form.getValue('internal_user');
}
var params = {};
params.sysparm_parent_table = "sn_customerservice_case";
params.sysparm_parent_sys_id = g_form.getUniqueValue();
var ga = new GlideAjax('global.CatalogUtilsAjax');
ga.addParam('sysparm_name', 'getCatalogItemsByUserId');
ga.addParam('sysparm_user_name', userId);
ga.getXMLAnswer(itemParse);
function itemParse(response) {
var itemChoice = JSON.parse(response);
var fields = [
{
type: 'choice',
name: 'selectItem',
label: getMessage('Select the catalog item you want to request'),
choices: itemChoice,
mandatory: true
},
];
g_modal.showFields({
title: 'Create Request',
fields: fields,
size: 'lg'
}).then(function(fieldValues) {
g_service_catalog.openCatalogItem('sc_cat_item', fieldValues.updatedFields[0].value, params);
});
}
}
GlideAjax
getCatalogItemsByUserId: function(){
var user_id = this.getParameter("sysparm_user_name");
var items = new global.CatalogUtils().getCatalogIdsByUserId(String(user_id));
return JSON.stringify(items);
},
Script include
getCatalogIdsByUserId: function(userId) {
//Get user's user criteria's
var getCriterias = new sn_uc.UserCriteriaLoader.getUserCriteria(userId, 'sc_cat_item_user_criteria_mtom');
var options = [];
//filter catalog items available for
var gr = new GlideRecord("sc_cat_item_user_criteria_mtom");
gr.addEncodedQuery('user_criteria.sys_idIN' + getCriterias + '^sc_cat_item.active=true');
gr.query();
while (gr.next()) {
if (gr.sc_cat_item.getDisplayValue())
options.push({
'value': String(gr.sc_cat_item.sys_id),
'displayValue': gr.sc_cat_item.getDisplayValue()
});
}
//sort display value alfabetical
options.sort(function(a, b) {
if (a.displayValue < b.displayValue) {
return -1;
}
if (a.displayValue > b.displayValue) {
return 1;
}
return 0;
});
return options;
},