Advanced condition on a notification

palmen
Tera Guru

We want a notification to be send only when the ticket is updated by someone else then the person/s on work notes list.

Is this possible to script with an advanced condition?

 

What I've been trying without success is the following two examples

 

if (current.work_notes_list != current.sys_updated_by){

  answer = true;

}

 

OR

 

if (current.work_notes_list.user_name != current.sys_updated_by){

  answer = true;

}

 

I always get it to return true even if it's updated by the person who is in the "work notes list" field.

1 ACCEPTED SOLUTION

i hate it when at times you get a sys_id, and then when you want it, you have to dig to get it.




var gr = new GlideRecord('sys_user');


gr.query('user_name',current.sys_updated_by);


gr.query();


if (gr.next())


{    


      uid = gr.sys_id;


      if(current.work_notes_list.toString().indexOf(uid) != -1)


              answer = true;


      else


              answer = false;


}


else


      answer = false;




If the user cannot be found in the sys_user table, it will not send - change line 13 to switch that



If it finds a matching user, it then looks and if the user Id is in the work_notes_list, it will send otherwise it will not


you can switch it by adding an ! at line 7, or swapping lines 8 and 10 around



Cheers


View solution in original post

14 REPLIES 14

I don't get this to work, now there are no notifications being send.


I've tried it by impersonating the user on work notes list and also tried it with my user, no mail was send in any of the cases.


i hate it when at times you get a sys_id, and then when you want it, you have to dig to get it.




var gr = new GlideRecord('sys_user');


gr.query('user_name',current.sys_updated_by);


gr.query();


if (gr.next())


{    


      uid = gr.sys_id;


      if(current.work_notes_list.toString().indexOf(uid) != -1)


              answer = true;


      else


              answer = false;


}


else


      answer = false;




If the user cannot be found in the sys_user table, it will not send - change line 13 to switch that



If it finds a matching user, it then looks and if the user Id is in the work_notes_list, it will send otherwise it will not


you can switch it by adding an ! at line 7, or swapping lines 8 and 10 around



Cheers


This one works!


I had to switch line 8 and 10 to make it work though.


Thanks a lot for the help.


Kalaiarasan Pus
Giga Sage

how is the notification being triggered? by firing a event using a before rule or a after business rule? or using record updated on the notification template ?


this should be your base script ....



var answer = false;


var notes = current.work_notes.getJournalEntry(-1);


var currentUser = gs.getUser().getDisplayName();


var na = notes.split("\n\n");


for (var i = 0; i < na.length; i++)


  {


  if(na[i].indexOf(currentUser) != '-1')


  {


  answer = true;


  break;


  }


}


if(!answer)


  {


  gs.addInfoMessage("Fire Event");


}