- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 08:44 AM
I have a request where they want to check if the opened requested item exists for the current Requested For. If yes, don't generate another RITM.
I am assuming this is a business rule but I don't know how to execute this request. Any help would be much appreciated
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 12:01 PM
If you want to prevent the submission of the request, the below code will work - assuming there is a variable that is populated when submitting on behalf of someone else. When the Order Now or Add to Cart buttons are clicked an alert will pop up if an active RITM for the same requested for and catalog item exists.
onSubmit catalog client script
function onSubmit(){
var url = document.URL.parseQuery();
var itemsysid = decodeURI(url['sysparm_id']); //gets the sysid of this catalog item
var ajax = new GlideAjax('BKBDupeCheck'); //name of your script include
ajax.addParam('sysparm_name', 'checkDupeRITM'); //name of the function in the script include
ajax.addParam('sysparm_user', g_form.getValue('v_requested_for')); //name of the variable to submit on behalf of someone else
ajax.addParam('sysparm_sysid', itemsysid); //pass in the catalog item
ajax.getXMLWait(); // process the server script and wait for a response
var answer = ajax.getAnswer(); // return value from server script
if(answer == 'true'){
alert("There is already and active request of this type for this user");
return false; //prevent submission of the request
}
}
script include - be sure Client callable is checked
var BKBDupeCheck = Class.create();
BKBDupeCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkDupeRITM: function () {
var answer = 'false';
var usr = this.getParameter('sysparm_user');
var catitem = this.getParameter('sysparm_sysid');
var gr = new GlideRecord('sc_req_item');
gr.addQuery('cat_item', catitem);
gr.addQuery('request.requested_for', usr);
gr.addQuery('active', true);
gr.query();
if(gr.next()){
answer = 'true';
}
return answer;
},
type: 'BKBDupeCheck'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 09:06 AM
Is this via a workflow? Can you possibly attach a flow diagram of this logic?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 09:15 AM
this should be done as a business rule, as it shouldn't trigger the workflow if a previous request exists
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 09:45 AM
If you want the user to receive feedback so that they know the attempted request cannot be submitted, you'll likely need an onSubmit catalog client script with a GlideAjax call to a script include, then if whatever criteria matches it would display a message and not allow the request to be submitted. The other approach is a before insert business rule that would check the same criteria. I'll try to mock one up as I'm not sure how smoothly this would work with the cart -> REQ -> RITM ordering process before displaying the order summary.
What is your criteria to disallow?
1) An active RITM where requested_for (of the REQ) = current user - or do you have a variable where they can request on behalf of someone else?
2) and the catalog item is the same - or do you need to match on some other variable-driven criteria?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2020 10:01 AM
thank you for your answer brad!
they can request on someone elses behalf. the catalog item is to replace a manager of a group.
the goal is to check if there is an open ritm for the requested for, for the current catalog item. this should be done as a server side script since it is querying the ritm table. so it would have to be a business rule. the variable is the standard requested_for
i dont need to match any variables. i just need to check if there is a current ritm open for the requested_for user.