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
and what error do you get?
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
it seems that your script include doesn't query because of missing (). See below highlighted in red:
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;
//should be gr.query();
if (gr.next()) {
proFound = 'true';
} else {
proFound = 'false';
}
return proFound;
},
type: 'CATdupcheck'
});
EDIT: and alternatively, try to return true/false (boolean), not "true"/"false" (string)
/* If my response wasn’t a total disaster ↙️ ⭐ drop a Kudos or Accept as Solution ✅ ↘️ Cheers! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
I made the corrections as you suggested. I did a test and im getting a popup that just says FALSE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
project variable is reference type?
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