How to disable a notification if another notification is already sent ?

Mandy11
Tera Contributor

Hello all,
I have 2 notifications that can be sent at the same time.
1. A notification when a ticket is commented 
2. A notification when a person is quoted in a comment
I would like to block the second notification if the person has already received the first notification.
The 2 notifications do not use the same table
Notification 1 :

find_real_file.png

Notification 2 :

find_real_file.png

Does anyone have an idea how to do this?

Thanks

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

As the two are from different tables, there is no easy toggle to do this. Assuming you want to suppress the @mention email, you could suppress it by adding an advanced condition to filter if the notifee is the caller, member of the watchlist etc.

A potential solution to append onto the existing advanced condition. This checks if the user is present in one of the user fields. Update the fieldsToCheck array with the fields from your other notification.

function notAlreadyNotified(){
	var document = current.document.getRefRecord();
	//If we can't get a GlideRecord object from the document field
	//Assumption is to allow this email to send for safety
	if(!document.isValidRecord())
		return true;
	var user = current.getValue("profile");
	var fieldsToCheck = ["caller_id" , "watch_list" , "work_notes_list" , "assigned_to"];
	
	return fieldsToCheck.some(function(field){
		if(!document.isValidField(field))
			return false;
		
		var fieldType = document.getElement(field).getED().getInternalType();
		
		if(fieldType == "reference")
			return document.getValue(field) == user;
		
		if(fieldType == "glide_list"){
      var list = document.getValue(field);
      if(gs.nil(list))
        return false;
			return document.getValue(field).indexOf(user) > -1;
    }
		
		return false;
		
	});
}
shouldSend() && notAlreadyNotified();

View solution in original post

4 REPLIES 4

Kieran Anson
Kilo Patron

As the two are from different tables, there is no easy toggle to do this. Assuming you want to suppress the @mention email, you could suppress it by adding an advanced condition to filter if the notifee is the caller, member of the watchlist etc.

A potential solution to append onto the existing advanced condition. This checks if the user is present in one of the user fields. Update the fieldsToCheck array with the fields from your other notification.

function notAlreadyNotified(){
	var document = current.document.getRefRecord();
	//If we can't get a GlideRecord object from the document field
	//Assumption is to allow this email to send for safety
	if(!document.isValidRecord())
		return true;
	var user = current.getValue("profile");
	var fieldsToCheck = ["caller_id" , "watch_list" , "work_notes_list" , "assigned_to"];
	
	return fieldsToCheck.some(function(field){
		if(!document.isValidField(field))
			return false;
		
		var fieldType = document.getElement(field).getED().getInternalType();
		
		if(fieldType == "reference")
			return document.getValue(field) == user;
		
		if(fieldType == "glide_list"){
      var list = document.getValue(field);
      if(gs.nil(list))
        return false;
			return document.getValue(field).indexOf(user) > -1;
    }
		
		return false;
		
	});
}
shouldSend() && notAlreadyNotified();

Thank you  for your help.
I tested your code and adjusted it a bit to make it work properly.
Instead of taking the profile I took the user field for the variable "user".

function alreadyNotified(){
	var document = current.document.getRefRecord();
	//If we can't get a GlideRecord object from the document field
	//Assumption is to allow this email to send for safety
	if(!document.isValidRecord())
		return true;
	var user = current.getValue("user");
	var fieldsToCheck = ["caller_id" , "watch_list" , "work_notes_list" , "assigned_to"];
	
	return fieldsToCheck.some(function(field){
		if(!document.isValidField(field))
			return false;
		
		var fieldType = document.getElement(field).getED().getInternalType();
		
		
		if(fieldType == "reference")
			return document.getValue(field) == user;
		
		if(fieldType == "glide_list"){
      var list = document.getValue(field);
      if(gs.nil(list))
        return false;
			return document.getValue(field).indexOf(user) > -1;
		}
		
		return false;
		
	});
}

shouldSend() && !alreadyNotified();

Hi,

If Kieran's reply guided you Correctly, please mark that reply as Correct.

If any other were Helpful, please mark those as Helpful.

Take care! 🙂


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Allen Andreas
Administrator
Administrator

Hi,

It's a bit complex to try and decipher if a user has been sent one notification over the other in that moment as one factor can be "timing".

Do you know which notification is sent first between these two? Is Notification 2 really sent after notification 1 (have you tested this).

Say you determine that notification 2 does really send after notification 1, also say you could query emails and see if this particular email has been sent and one of the recipients of that email is this user, are you going to further check that this all happened within the past minute? 30 seconds?

Hopefully you can understand where I'm coming from and so more information from you would be needed to help prevent this additional email from sending.

It's not as simple as saying if you get this one, don't get that one.

You'd have to build the logic to check for that. The logic can be complex or simply, depending.

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!