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

sola2
Tera Contributor

Hello @Seraj, thank you for your assistance.  Do you know how could we include the ticket number of the already existing ticket with those conditions?  so it says: 'INC# already exist with caller and description, please update your current ticket'

 

Use:

 

 

gs.addErrorMessage('Incident ' + gr.number + ' Desc: ' + gr.short_description + ' already exist with caller and description. Please update your current ticket.');

 

 in Seraj's script. or use gr.description instead of gr.short_description in the above if you want that field's value.

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

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

 

 

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