How to query assignment group from tasks table?

zsquared
Tera Contributor

Hello,

I am trying to query the assignment_group in my tasks table but I think I am hitting an error due to my lack of understanding the user groups.  

I want to filter for the assignment group called AOM-OU. I tried replacing assignment_group with sys_user_group since I noticed that this was a reference field in the form.

var tasks = new GlideRecord('sc_task');

tasks.addQuery('sys_user_group', 'AOM-OU');

tasks.query();

This should be a simple query but I'm not sure where I am going wrong...

1 ACCEPTED SOLUTION

Deepak Kumar5
Kilo Sage
  1. var tasks = new GlideRecord('sc_task');  
  2. tasks.addQuery('assignment_group', 'sys_ID');   //sys Id of assignment group
  3. tasks.query();

View solution in original post

11 REPLIES 11

Yeah!


I went to user groups in servicenow and then clicked into the user group and right clicked to copy over the sys ID


Hi Zhen



Thanks for the revert



I am new to service now and still learning, I wanted to enquire where the below code was put/checked by you in SNow...



  1. var tasks = new GlideRecord('sc_task');
  2. tasks.addQuery('assignment_group', 'sys_ID');   //sys Id of assignment group
  3. tasks.query();


was it business rule/script ???



Thanks in advance


So I needed to query for data from the tasks table that had a certain sys_id to another table.   In order to do this, I used a scheduled job since I need to capture the data on a monthly basis.   And then I click 'Execute' to execute the script so I can see the results.   Let me know if you have further questions!


Could you tell me where did you run the script and what where the conditions used, if any


System Definition > Scheduled Jobs


Create a new scheduled job




//this defines the where I want to pull data from


//so I am pulling data from the sc_task table, with the specific assignment group with sys_id of 103847533dfww


var tasks = new GlideRecord('sc_task');


tasks.addQuery('assignment_group', '103847533dfww');   //sys Id of assignment group


tasks.query();



//so if the script finds any data that meets the above criteria


//do this to each record...


while (tasks.next()) {


        //place the data in the following table:


        var table = new GlideRecord('u_table');


        //look for the field name in the table called u_assignment_group


                  table.u_assignment_group = tasks.assignment_group.getDisplayValue();


        //insert the data record in the field


                  table.insert();


}