Restrict submit catalog item if short description and Requester is same

Samiksha2
Mega Sage

Hi All,

 

Users are creating request through emails. The requirement is to restrict to create request if short description and requested for is same. And the existing record is true.

I read some articles and posts but I didnt find the correct solution.

 

Please help.

 

Thanks,

Samiksha

17 REPLIES 17

Hi @Samiksha2 ,

You can achieve your requirement by writing on before (insert) Br for checking existing open RITMs. 

Hi @Vengateshwaran ,

Can you help me with the script.

 

Thanks

Hello @Samiksha2 ,

                                   You can try below before insert Business rule to achieve.

(function executeRule(current, previous /*, gs */) {
   // Get the short description and requested for values from the current record
   var shortDescription = current.short_description;
   var requestedFor = current.requested_for;

// you can use addEncodedquery as well    
// var encodedQuery = "descriptionLIKE"+shortDescription +"^requested_for="+requestedFor;
   // Create a GlideRecord query to check for existing records
   var existingRecord = new GlideRecord('incident'); // Change 'incident' to your table name
// existingRecord.addEncodedQuery(encodedQuery );  
   existingRecord.addQuery('short_description', shortDescription); // 
   existingRecord.addQuery('requested_for', requestedFor);
   existingRecord.addQuery('sys_id', '!=', current.sys_id); // Exclude the current record
   existingRecord.query();

   if (existingRecord.next()) {
      // An existing record with the same short description and requested for exists
      gs.addErrorMessage("A similar request already exists."); // for testing purposr only 
      current.setAbortAction(true);// Abort the record creation/update
   }
})(current, previous);

Kindly mark correct and helpful if applicable

Hi @Chetan Mahajan ,

For different short description also requested item is not generating.

 

Thanks,

Samiksha

Hello @Samiksha2 ,

                                   Please try with encodedQuery I have already mentioned in my Response.

Thanks,

Chetan