Business rule help - Stop insert on conditon

Andrew18
Giga Expert

Hi all, we have a custom table which is pulling in asset information, however we dont want IPhone records to create. I've tried the below business rule but having no joy, anyone know where I'm going wrong?

 

 

(function executeRule(current, previous /*null when async*/ ) {

    var device = current.u_device_type;

    if (device == "IPhone") {

        current.setAbort(true);
    }
})(current, previous);

 

 

5 REPLIES 5

Peter Bodelier
Giga Sage

Hi @Andrew18 

 

It's current.setAbortAction(true);

 

 


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.

Hi, thanks for coming back to me, I've tried this function before no joy sorry.

Vishal Birajdar
Giga Sage

Hi @Andrew18 

 

Use before -insert business rule

You can use filter condition in "when to run" as Device type is Iphone

and in "Action" section select setAbort to true

 

Vishal Birajdar
ServiceNow Developer

I know one thing, and that is that I know nothing.
- Socrates

Andrew18
Giga Expert

Thanks everyone...

I fixed it! I was missing the current.operation() == 'insert';

(function executeRule(current, previous /*null when async*/ ) {

    if (current.operation() == 'insert' && current.u_device_type == "iPhone") {

            current.setAbortAction(true);
        }
})(current, previous);