how to get the list of tasks assigned to a particular user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2020 01:50 AM
requirement is...i have form where one field is reference to user table....other field is location field.
when i select a user i want users previous worked location to be populated.
for that first i need to know how many tasks are assigned to that user.
then from that i want to know what is the previous one and the later one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2020 04:33 AM
Hi Pravallika,
Where do you have the information about the previous worked location?
You need to be careful when you say you tasks assigned to that user. There are many types of tasks. All tasks exist in the task table. There are numerous tables that extend task, e.g. incident_task, problem_task, change_task, etc. You can define a related list to any or all of them based on the connection between the sys_id of the user record and assigned_to on the task record.
If you want to get the full set of tasks assigned to a user in descending chronological order you use a script like this:
var theTasks = new GlideRecord("task");
theTasks.addQuery("assigned_to", current.sys_id);
theTasks.orderByDesc("sys_created_on");
theTasks.query();
theTasksCount = theTasks.getRowCount();
From there you proceed based on the value of theTaskCount. If the value is 2 or greater you can get the most recent task and the one before it. This script gets all entries in the task table assigned to the user if you only want one type of task substitute that table name for task. If you want several types of tasks, you can limit those entries by filtering task on sys_class_name (shows onscreen as task type).
If you want to populate when the record opens on screen, you'll need an On Load client script to call the script include above via AJAX. Make sure that you set that script include to be client callable. Here's the link to the documentation about AJAX.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2020 09:07 PM
hai John,
Thanx for the reply..
but can you be more specific about below part....
"From there you proceed based on the value of theTaskCount. If the value is 2 or greater you can get the most recent task and the one before it. This script gets all entries in the task table assigned to the user if you only want one type of task substitute that table name for task. If you want several types of tasks, you can limit those entries by filtering task on sys_class_name (shows onscreen as task type)"...
i am getting the row count but the list i am not getting...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2020 07:48 AM
Hi Pravallika,
You can do something like this:
var theTasks = new GlideRecord("task");
theTasks.addQuery("assigned_to", current.sys_id);
theTasks.orderByDesc("sys_created_on");
theTasks.setLimit(2); //you only need two records
theTasks.query();
theTasksCount = theTasks.getRowCount();
var lastRecord = "---none---"; //initialize them to avoid scope issues
var previousRecord = "---none---"; //ditto
if (theTasksCount > 0) {
theTasks.next();
lastRecord = theTasks.<lastLocation>; //insert the name of the field you need
if (theTasks.next()) { //if there is a second record
previousRecord = theTasks.<lastLocation>;
}
}
//from here you have the values or ---none--- so you can do whatever you need
Please feel free to come back if you have further questions.
Hope that helps.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-04-2020 10:43 PM
hai john,
thanks for the code...
but how to define the previous location is the issue here...
var tasks = new GlideRecord("wm_task");
tasks.addQuery('assigned_to', wotassignedto);
tasks.addEncodedQuery("work_startONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()");
tasks.orderBy('work_start');
tasks.query();
while (tasks.next()) {
if (tasks.getRowCount() == 1) {
var users = new GlideRecord("sys_user");
users.addQuery('sys_id', wotassignedto);
users.query();
if (users.next()) {
gs.addInfoMessage("user related" + users.location);
fromlocation = users.location;
}
tolocation = wotlocation;
}
if (tasks.getRowCount() > 1) {
if (wotactualstart > tasks.work_start && tasks.work_end != '') {
//gs.addInfoMessage("task related" + tasks.location);
fromlocation = tasks.location;
gs.addInfoMessage("task related" + fromlocation);
}
tolocation = wotlocation;
}
}
i have tried to acheive the previous location based on work end field...but not able to acheive...can you say where i am wrong