Check Active catalog Items for Duplicates if user trys to submit new one
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I have a Catalog item (request project name) and when one is submitted it has to go through the approval process. Users are submitting again because they are not finding it in the system becuase it hasn't been completed yet. we need to stop users from submitting duplicate where there are active requests for the same Item. to do this we have a Variable called "Project name" and that is a readonly field that is built from other fields. I tried building a script include and a catalog Client script but im getting errors and i don't know why so im asking for you assistance..
SCRIPT INCLUDE
var CATdupcheck = Class.create();
CATdupcheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hasActive: function() {
var project = this.getParameter('sysparm_project');
var catItem = this.getParameter('sysparm_cat_item');
var proFound = 'no';
if (!project || !catItem)
proFound = 'false';
var gr = new GlideRecord('sc_req_item');
gr.addActiveQuery();
gr.addQuery('cat_item', catItem);
gr.addQuery('variables.u_project_name', project);
gr.setLimit(1);
gr.query;
if (gr.next()) {
proFound = 'true';
} else {
proFound = 'false';
}
return proFound;
},
type: 'CATdupcheck'
});
CATALOG CLIENT SCRIPT
Function onSubmit() {
var project = g_form.getValue('u_gcp_project_name');
if (!project) return true;
var catItemSysID = 'b18c688d1b1a09100151657ae54bcbaa';
var ga = new GlideAjax('CATdupcheck');
ga.addParam('sysparm_name', 'hasActive');
ga.addParam('sysparm_project', project);
ga.addParam('sysparm_cat_item', 'b18c688d1b1a09100151657ae54bcbaa');
ga.getXMLAnswer(doSomething);
function doSomething(answer) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if (answer === 'true') {
g_form.addErrorMessage('A CAT request for "' + project + '" is currently submitted and waiting approval. Please wait for it to complete before submitting a new one.');
return false;
}
return true;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I will suggest this
1) don't make that variable read-only
2) let users select and you can add reference qualifier to that so that user doesn't select that project
The ref qualifier will not show those projects for which RITM is still active.
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
3 weeks ago - last edited 3 weeks ago
No the field is a Single line text field that is being built from other Varaibles. the selection build that project name not the user. it's read only because of that reason
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
if it's read-only then based on what the logic which auto populate the Project, you add logic to validate there and not in onSubmit.
Without screenshots can't help much.
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