Sending notification only to itil users of a particular company

prudhvig
Tera Expert

Hi,

I have a notification configured on the Time Card Application which notifies users who have not submitted the time sheets. It sends out notifications to all the users in Servicenow on Monday irrespective of the user's company. That way, the notification has been sent out to all clients also which has become a problem.

Below is my notification:

Screenshot (832).png

Screenshot (833).png

Screenshot (834).png

I need to send that notification out only to itil users of my company. (not to everyone). Please guide me in solving this as I am newbie.

Thanks in advance.

4 REPLIES 4

Nate23
Mega Guru

in the advanced condition of your notification you can script the condition of whether of not the user has itil role or not.


for reference:


Advanced conditions for email notifications


Hi Nathan,



I have a Scheduled Job which fires an event in the Registry. This event has been named in the notifcation. So, I guess it's better adding condtional in the Scheduled JOb itself. Below is the Scheduled Job:



find_real_file.png



This should be better right? Please let me know.


I would change the sys_user query at the beinning to this:



var userNoTimeCard = new GlideAggregate('sys_user_has_role');


var company = 'sys_id_of_company';


var role = '282bf1fac6112285017366cb5f867469';//oob itil role


userNoTimeCard.addEncodedQuery('user.company='+company+'^state=active');


userNoTimeCard.addQuery('role',role);


userNoTimeCard.groupBy('user');


userNoTimeCard.query();


while(userNoTimeCard.next()){


//enter the rest of your code here


//in the logic of your code just add 'user' after you reference the userNoTimeCard object.


//ie: line 4 you reference it like userNoTimeCard.userName.toString() that would change to userNoTimeCard.user.userName.toString()


}


any updates on if this worked?