- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2025 11:20 PM
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 01:14 AM
Try below approach.
- Write an onChange client script on primary contact as below"
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue == '') { return; } // Call GlideAjax to check existing RITMs var ga = new GlideAjax('CheckUserRITMs'); ga.addParam('sysparm_name', 'hasExistingRITM'); ga.addParam('sysparm_user_id', newValue); ga.addParam('sysparm_catalog_item', g_form.getUniqueValue()); // catalog item sys_id ga.getXMLAnswer(function(response) { if (response == 'true') { g_form.showFieldMsg('primary_contact', 'This user has already requested this item.', 'error'); //check field name } else { g_form.hideFieldMsg('primary_contact', true); //check field name } }); }
- Write a New Client callable script include as below
Name: CheckUserRITMs
Accessible from: All application scopes
Client Callable: Truevar CheckUserRITMs = Class.create(); CheckUserRITMs.prototype = Object.extendsObject(AbstractAjaxProcessor, { hasExistingRITM: function() { var userId = this.getParameter('sysparm_user_id'); var catalogItemId = this.getParameter('sysparm_catalog_item'); if (!userId || !catalogItemId) { return 'false'; } var ritmGR = new GlideRecord('sc_req_item'); ritmGR.addQuery('cat_item', catalogItemId); ritmGR.addQuery('u_primary_contact', userId); // replace with actual field name if different ritmGR.query(); if (ritmGR.hasNext()) { return 'true'; } return 'false'; } });
This will show an error message at the field level and also user cannot submit even if they click the order button.
Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 06:47 AM
it seems script include is not getting called and hence the 3 parameters are coming as empty
a) account variable refers to which table?
b) the onChange is running on which table? that variable refers to which table?
Client Script:
1) pass the catalog item sysId as hard-coded value
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (g_user.hasRole('agent_workspace_user')) {
alert('welcome');
var ga = new GlideAjax('BT_CSR_SSR_CatalogUtils');
ga.addParam('sysparm_name', 'hasExistingRITM');
ga.addParam('sysparm_user_id', newValue);
ga.addParam('sysparm_account', g_form.getValue('account'));
ga.addParam('sysparm_catalog_item', 'catalogItemSysId'); // catalog item sys_id
ga.getXMLAnswer(function(response) {
alert(response);
if (response == 'true') {
alert(true);
g_form.showFieldMsg('contact_name', 'This user has already requested this item.', 'error'); //check field name
} else {
alert(false);
g_form.showFieldMsg('contact_name', 'This user has already nottttt requested this item.', 'error'); //check field name
}
});
}
}
Script Include: it should be client callable
1) pass the correct sysparm name
var BT_CSR_SSR_CatalogUtils = Class.create();
BT_CSR_SSR_CatalogUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hasExistingRITM: function() {
var checkingRITM;
var userId = this.getParameter('sysparm_user_id');
var catalogItemId = this.getParameter('sysparm_catalog_item');
var userAccount = this.getParameter('sysparm_account');
gs.info('agentIsh279 ' + userId);
gs.info('agentIsh280 ' + catalogItemId);
gs.info('agentIsh281 ' + userAccount);
var ritmGR = new GlideRecord('sc_req_item');
ritmGR.addEncodedQuery('cat_item.sys_id=' + catalogItemId + '^company.sys_id=' + userAccount + '^requested_for.sys_id=' + userId);
ritmGR.setLimit(1);
ritmGR.query();
gs.info('agentIsh292 ' + ritmGR.getRowCount());
return ritmGR.hasNext().toString();
},
type: 'BT_CSR_SSR_CatalogUtils'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 12:04 AM
one Uc is there to control the visibility on the support portal.
But now I need to control it on the workspace
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 12:25 AM
that user criteria should work when you open the catalog from workspace also
Did it not work?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 12:39 AM
@Ankur Bawiskar For the visibility of item to the customer(for this we have a different logic). this is working fine
for agent we have this logic how to implement this
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 12:58 AM
you can have catalog client script on your variable and use GlideAjax to validate
If already record exist then show error message on that variable and user won't be able to submit the form
what did you start with and where are you stuck?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 12:00 AM
You can write a on change catalog client script on primary contact variable.
In the script you can check if the RITM already exists for the combination. If the RITM exists then you can display an alert or message as per your need and clear the selected Primary contact. This way you wont have to deal with disabling the order now button.
Please mark the answer helpful and correct if it helps the issue. Happy scripting 🙂
-Shantanu