business rule

sola2
Tera Contributor

Does anyone know how can you prevent an incident from getting submit if the current caller already has an active ticket with the same description?

3 ACCEPTED SOLUTIONS

Community Alums
Not applicable

Hi @sola2 ,

I tried your probem in my PDI and it works for me please refer below steps 

1. Create Before Business rule and insert is checked 

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

	// Add your code here
	var gr = new GlideRecord('incident');
	gr.addQuery('caller_id',current.caller_id);
	gr.addQuery('description',current.description);
	gr.query();
	if(gr.next())
	{
		gs.addErrorMessage('Caller is assgined to same incident before. Please check before creating');
		current.setAbortAction(true);
	}

})(current, previous);

SarthakKashyap_0-1714818921360.png

Result 

 

SarthakKashyap_1-1714819009573.png

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 
Sarthak

 

 

View solution in original post

Krushna R Birla
Kilo Sage

Hi @sola2 

 

To achieve this requirement, you need to create before insert business rule. Please refer below snapshots for your reference,

 

KrushnaRBirla_0-1714820317933.png

 

Use below code,

 

(function executeRule(current, previous /*null when async*/) {
    var grInc = new GlideRecord('incident');
    grInc.addQuery('caller_id', current.caller_id);
    grInc.addQuery('description', current.description);
    grInc.query();
    if (grInc.next()) {
        gs.addErrorMessage("You can't create incident as there is other active incident present with same desciption");
        current.setAbortAction(true);
    }
})(current, previous);
 
Also, just to add for your information, it's not a good practice to add this kind of requirement, as customers/end users may encounter the same issue repeatedly. Therefore, we should not restrict creating incidents.
 

This will definitely helps you to resolved your issue. Let me know in case you need to understand the flow or you can DM on LinkedIn.

 

If this solution resolves your query, kindly mark it as the accepted solution and give it a thumbs up.

 

Best Regards,
Krushna Birla

View solution in original post

Hi @sola2 

Just you need to modify the message within if loop statement

Just paste this script:

gs.addErrorMessage(gr.number+' Already exist with caller '+gr.caller_id.getDisplayValue()+' and Description -  '+gr.description);
		current.setAbortAction(true);

 BR script.PNGtest record.JPG

Best Regards

Seraj

View solution in original post

9 REPLIES 9

Sandeep Rajput
Tera Patron
Tera Patron

@sola2 Please create an onBefore business rule on the incident table as follows.

Screenshot 2024-05-04 at 7.55.36 AM.pngScreenshot 2024-05-04 at 7.56.39 AM.png

Here is the script.

 

(function executeRule(current, previous /*null when async*/ ) {
var glideAgg = new GlideAggregate('incident');
glideAgg.addActiveQuery();
glideAgg.addQuery('caller_id',current.caller_id);
glideAgg.addQuery('description',current.description);
glideAgg.addAggregate('COUNT');
glideAgg.query();
if(glideAgg.next()){
	var incidentCount = glideAgg.getAggregate('COUNT');
	if(incidentCount>0){
		gs.addErrorMessage('An active incident with same caller and description already exist');
		current.setAbortAction(true);
	}
}

})(current, previous);

Please mark the answer helpful and correct if it manages to address your issue.

Hi @sola2 
You can do this using Before Insert Business Rule 
and add below script in scripting section

I am attaching Screenshot for your reference

RavindraYadav_1-1714800440609.png



RavindraYadav_2-1714800447200.png



 var gr = new GlideRecord('incident');
    gr.addActiveQuery();
    gr.addQuery('caller_id', current.caller_id);
    gr.query();
    while (gr.next()) {

        if (gr.description == current.description) {
            gs.addErrorMessage('This Caller has Active Incident');
            gr.setAbortAction(true);
        }
    }

AndersBGS
Tera Patron
Tera Patron

Hi @sola2 ,

 

Why would you do this? Do you have many users creating multiple incidents due to same issue? To base the incident on the description field is not good practice, is a string field content changes if there is just one more capital letter, a period has been removed etc.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

Best regards

Anders 

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Seraj
Tera Guru

Hi @sola2 

Just create one business rule on incident table and use the following:

Select trigger condition When- ' before ' and insert checkbox as true

Activate advance checkbox for scripting and

Try this BR script -

 

 

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

	var gr=new GlideRecord('incident');
	gr.addQuery('caller_id',current.caller_id);
	gr.addQuery('description',current.description);
	gr.query();
	if(gr.next())
	{
		gs.addErrorMessage('Incident already exist with caller and description');
		current.setAbortAction(true);
	}
})(current, previous);

 

 

BR 1.PNGBR 2.PNG

incident same.PNG

Best Regards

Seraj