Prevent duplicate submission on REQ/RITM

Leonardo Chave1
Kilo Sage

Hi SNow community,

I'm having some issues with a BR where it prevents the duplication of RITM's based on the variables input. In this case, if the user request a service which he already submit earlier it would avoid the RITM creation but on the other hand it's creating an empty REQ record. So i'm requesting your help to see how to avoid the creation of the empty REQ.

BR on Requested Item (sc_req_item)
When to run: before
script:

var gr = new GlideRecord('sc_req_item');
gr.addQuery('request.requested_for', current.variables.caller);
gr.addQuery('business_service', current.variables.service);
gr.addQuery('state', '!=', '7');

gr.query();

if (gr.next()) {
current.setAbortAction(true);
gs.addErrorMessage('There is already a RITM with the same service.'); 
}


Thanks in forwards.

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

Instead of creating business rule, you should abort request submission after intake process.

e. you can configure on submit client script, Glideajax to validate if request is already present for same user and abort submission if request was already submitted.

 

Regards,

Sachin

Leonardo Chave1
Kilo Sage

Can you guide me, on new on this.

Create an onChange Catalog Client Script for the requested_for field.

OR you can reuse same code for onsubmit client script as well.

 

 

 

function onChange(control, oldValue, newValue, isLoading) {


      if (isLoading)


              return;


 


      g_form.hideFieldMsg('requested_for', true);


 


      if (newValue == '')


              return;


 


      var ga = new GlideAjax('AjaxFunctions');


      ga.addParam('sysparm_name', 'checkUserRequest');


      ga.addParam('sysparm_user', newValue); // User


      ga.addParam('sysparm_item', gel('sysparm_id').value); // Item


      ga.getXMLAnswer(function(answer) {


              if (answer && answer != 'none') {


                      var msg = 'This person already has an open Request(s) for this item: ' + answer;


                      g_form.showFieldMsg('requested_for', msg, 'error');


              }


      });


}

 

Create a Script Include:



Name: AjaxFunctions



Client-callable: true



var AjaxFunctions = Class.create();


AjaxFunctions.prototype = Object.extendsObject(AbstractAjaxProcessor, {


 


  checkUserRequest: function() {


          var user = this.getParameter('sysparm_user');


          var item = this.getParameter('sysparm_item');


 


          var requests = [];


          var ritm = new GlideRecord('sc_req_item');


          ritm.addActiveQuery();


          ritm.addQuery('requested_for', user);


          ritm.addQuery('cat_item', item);


          ritm.query();


          while (ritm.next()) {


                  requests.push(String(ritm.number));


          }


          if (requests.length > 0)


                  return requests.join(', ');


          return 'none';


  },


 


  type: 'AjaxFunctions'


});

 

Regards,

Sachin