how to get the list of tasks assigned to a particular user

Pravallika9
Tera Expert

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.

 

5 REPLIES 5

Hi Pravllika,

A few things come up, all indicating a need for context.  If I understand your requirement correctly, you want to populate a user's location based on a location field in you wm_task table.  The way that you describe the need, the location should come from one of the two most recent records in wm_task that were assigned to that user.

If that is the case, other criteria aside, you want to change this line

tasks.orderBy('work_start');

to

tasks.orderByDesc('work_start');

to get the most recent records.  Assuming that you are looking to update the user's location from your tolocation variable you need to add the following after the code you included:

if (tolocation != "") {
   users.setValue("location", tolocation);
   users.update();
}

Keep in mind that location in sys_user is a reference to cmn_location.  If your location field in wm_task is not a reference to cmn_location then you need to do the following to update the user location:

if (tolocation != "") {
   users.setDisplayValue("location", tolocation);
   users.update();
}

However, if the location in wm_test is not an exact match for the name field in cmn_location that can lead to issues downstream.  To be sure perhaps something like this is more appropriate

if (tolocation != "") {
   var theLocation = new Gliderecord("cmn_location");
   if (theLocation.get("name", tolocation) {
      users.setValue("location", theLocation.sys_id);
      users.update();
   }
   else {
      gs.addErrorMessage("Unable to find location " + tolocation)  //replace with however you want to process this
   }
}

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster