How can we check the requested for user, if he has already raised request subsequently popup message needs to be displayed underneath respective field??

Lakshmiprasann6
Tera Contributor

Hi,

How can we check if requested for user has already raised request? How can we stop submission of form if request is already existed for user who has been selected in requested for field. I tried with hidden field but I wanted to understand best approach for this requirement.

Since DOM manipulation if used in client script and will not be possible from portal and synchronous also will not be working from portal and Gliderecord should not be used in client script.

I would like to know the best approach for this.

 

 

4 REPLIES 4

Musab Rasheed
Tera Sage
Tera Sage

Hello,

Below thread has solution , please check

https://community.servicenow.com/community?id=community_question&sys_id=e30a4d45dbe014505129a851ca96197b

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Yousaf
Giga Sage

Hi,
try this

onSubmit Catalog Client Script
function onSubmit() {
 var catitem = gel('sysparm_id').value; //This works in the native Service Catalog UI only, not Portal (getUniquieValue or something like that)
 //note that gel is not best practice, but necessary in this case. Ensure the Isolate script field on the catalog client script is unchecked
 var user = g_form.getValue('Requester');//assuming you have a reference variable with this name (case-sensitive);
 if(g_form.getValue('ConfirmInfoReqName') != ""){
  user = g_form.getValue('ConfirmInfoReqName');
 }
 var ga = new GlideAjax('RITMLookup'); //Name of the Script Include 
 ga.addParam('sysparm_name', 'getRITM'); //name of function in script include 
 ga.addParam('sysparm_catitem', catitem); 
 ga.addParam('sysparm_user', user); 
 ga.getXMLWait(); //generally not best practice, but necessary in this case to wait on the server result before processing the request

 var answer = ga.getAnswer (); 
 if (answer != ''){
  alert("This person already has pending request " + answer + " in the system. Only one request for a person may be open at a time.");
  return false;
 }
}

 

Next you will need to create a script include with the name referenced in the client script, ensuring that the Client callable box is checked.

var RITMLookup = Class.create();
RITMLookup.prototype = Object.extendsObject(AbstractAjaxProcessor, { 
 
 getRITM: function() {
  var answer = '';
  var user = this.getParameter('sysparm_user'); 
  var catitem = this.getParameter('sysparm_catitem'); 
  var check = new GlideRecord('sc_req_item');
  check.addQuery('stage', 'IN', 'Awaiting Approval, Awaiting Fulfillment');
  check.addQuery('request.requested_for', user);
  check.addQuery('cat_item', catitem); 
  check.query();
  while(check.next()){
   answer = answer += check.number + " ";
  }
 
  return answer;
 },
  
type: 'RITMLookup'
});

Checkout this link: https://community.servicenow.com/community?id=community_question&sys_id=e30a4d45dbe014505129a851ca96197b

 

Thanks,

Yousaf


***Mark Correct or Helpful if it helps.***

Hi Lakshmiprasanna if i helped you in any way can you mark my answer helpul or correct.

 

Thanks,
Yousaf


***Mark Correct or Helpful if it helps.***

Hi ,

The above solution doesn't work from portal.Could you suggest how can I make it effectively to work even from portal end as well?