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

ajbarnes
Tera Expert

I would have to test this, but I believe you are trying to compare a single entry in a field with a list. You would need to iterate through the list entries to do a real comparison.


OK, sounds like the solution. I'll have to test this later.


jsi
Mega Guru

Hi,


    yes..As Andrew said convert the work notes list field to string and separate the entries by comma/semicolon.Now iterate all   the entries and check.


Thanks!!


poyntzj
Kilo Sage

this should work.


if (current.work_notes.list.toString().indexOf(current.sys_updated_by) == -1)


answer=true;


else


answer = false;



the worknotes list is a list of ID's, so make into a string and then search that string using the sys_id of the person updating


If it is there, you get a value other than -1