The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Before Delete Business Rule

Bhushan_Salseka
Mega Expert

Hi All,

I have a requirement that if user click on Delete button on shopping cart page, then it should restrict to delete and print a info message on it.

So for this i have written a Before Delete Business Rule and it is restricting user to delete catalog item. But when i am opening any catalog item page that time that BR is running and it gives an info message before added to the cart.

I did not understand which functionality is affecting.

Can anyone suggest on it.

Below is the BR i have written.

BR is on "sc_cart_item" table.

function onBefore(current, previous) {

    gs.log('Inside On After function');

  var gr = new GlideRecord('sc_cart_item');

  gr.addQuery('cat_item' , 'c89e448b4f034e004430eb1e0210c751');

  gr.query();

  while(gr.next())

  {

  current.setAbortAction(true);

  gs.addInfoMessage('Should not be Deleted');

  gs.log('inside if for deletion message');

      }

}

Thanks in Advance.

Regards

Bhushan

6 REPLIES 6

larstange
Mega Sage

Hi,



Here is a fix that I have applied to a similar business rule that I have



//When an item is selected in the service catalog it is added and removed from the cart for some reason. We do not want this business rule to run when an item is created and deleted within 1 second


var diffSeconds = gs.dateDiff(current.sys_created_on.getDisplayValue(), gs.nowNoTZ().getDisplayValue(), true);


if (diffSeconds > 1) {


..your code


shaikbasha
Kilo Expert

Hello,



Rather than using GlideRecord in script try adding the same in condition part of business rule.



Either in 'when to run'   or 'condition part' in Advanced Section.



Thank you.


Hi Basha,


Thanks mfor the reply.


I have tried with conditions and when to run. But the issue is same.



Regards


Bhushan


Anyone have any idea ?