0

I need to find an user in a list to set the assignedto task property, these informations are in a list. So i use this method :

public static SPUser GetSPUser(SPListItem item, string key){ 
    SPFieldUser field = item.Fields[key] as SPFieldUser;

    if (field != null)
    {
        SPFieldUserValue fieldValue = field.GetFieldValue(item[key].ToString()) as SPFieldUserValue;
        if (fieldValue != null)
        {
            return fieldValue.User;
         }
     }
     return null;
 }

The problem is that when i use this method or this part of code, my workflow stop without saying anything. Here an exemple of code when i use it :

using (SPSite site = new SPSite(adress_of_my_site))
{                
    using (SPWeb web = site.OpenWeb())
   {
        SPList list = web.Lists["Acteurs du projet"];
        SPView view = cobj_ListeDesActeursDuProjet.DefaultView;
        SPListItemCollection itemcollection = list.GetItems(view);
        foreach (SPListItem item in itemcollection)
        {                       
            SPUser lobj_acteur = Utilities.GetSPUser(item,"acteur");
            // Dictionary<string,class>
            ActeursDuProjet[item["Rôle"].ToString()] = 
                new ActeursDuProjet()
                { 
                 Login = lobj_acteur.LoginName, 
                 Email = lobj_acteur.Email 
                };
        }

    }


}

If i comment the content of my foreach my workflow continue as well...

If anybody have an idea it will be cool.

Regards, Loïc

edit: problem in the code

LoKtO
  • 189
  • 2
  • 9
  • Have you tried debugging the code? Just attach Visual Studio to the w3wp process (if needed copy the debug .pdb file to the location where the .dll containing the code above is stored (bin directory or GAC) – Colin Jul 09 '09 at 14:09
  • Yes of course and no error... – LoKtO Jul 09 '09 at 14:26
  • So you've debugged while running the workflow and no error occurs? How do you know it stops at that specific loop content then? It just stops executing? – Colin Jul 09 '09 at 14:39
  • after this code activity i have a workflow task, the methodinvoking of the task execute, but nothing more after that. And in sharepoint the state of the workflow is terminate, and even if i try to modify my task to go in the invoked event of the task nothing happen – LoKtO Jul 09 '09 at 14:51
  • Is the Utilities.GetSPUser in a separate DLL (i.e. shared dll?). If so, is that loaded correctly (from GAC?) – Colin Jul 09 '09 at 14:59
  • no it's a class that i create in the workflow project, and even if i don't use the classe but just the code inside my foreach i have the problem. – LoKtO Jul 09 '09 at 15:04
  • Is the lobj_UnActeurDuProjet an SPListItem? ANd ["Rôle"] a field in that item? Maybe the field "Rôle" is not found? Does that field have an internal name use CAMLViewer (www.codeplex.com/SPCamlViewer) to check out a field's internal name. – Colin Jul 09 '09 at 15:23
  • lobj_UnActeurDuProjet is item ( i just forget to rename it :) ) and role is a field of item, i already test if my Dictionary is filled, and no problem with it :) – LoKtO Jul 09 '09 at 15:40

2 Answers2

1

Here are some debugging tips that might help:

ULS logs

Any exceptions should be reported here in some detail.

Enable debugging for all .NET code

This will cause the debugger to break whenever an exception occurs in SharePoint as well as your code. The downside is that the debugger will break on 'normal' exceptions that cause no side effects. So don't be misled!

To enable: Go to Debug, Exceptions and tick Common Language Runtime Exceptions. Also go to Tools, Options, Debugging and untick Enable Just My Code. Then attach to w3wp.exe.

Commenting code

You could also comment out all of your code. If the workflow step fails, you know there is a problem elsewhere. If the workflow step passes, then start uncommenting code until it fails - then you know where to look.

Alex Angas
  • 59,219
  • 41
  • 137
  • 210
  • nice :) My class are not marked as serializable so i have a serializationException Five minutes ago i try to comment my code and i found that the problem come from my dictionary or my class :) – LoKtO Jul 10 '09 at 08:58
0

I tried commenting this above but it didn't format nicely so here it is.

It probably is fine, but this looks fishy to me:

// Dictionary<string,class>
ActeursDuProjet[item["Rôle"].ToString()] = 
    new ActeursDuProjet()
    { 
     Login = lobj_acteur.LoginName, 
     Email = lobj_acteur.Email 
    };

I would think it would be something like:

// dictionary declared somewhere earlier
Dictionary<string,ActeursDuProjet> roles = new Dictionary<string,ActeursDuProjet>();

// inside the foreach
string role = item["Rôle"].ToString();
if (!roles.ContainsKey(role))
{
    ActeursDuProjet foo = new ActeursDuProjet();
    foo.Login = lobj_acteur.LoginName;
    foo.Email = lobj_acteur.Email;
    roles.Add(role, foo);
}
Kit Menke
  • 7,046
  • 1
  • 32
  • 54
  • yeah it could be this too :) i just use object initializers from 3.5 framework for the class. But the problem don"t seem to be about that :) – LoKtO Jul 09 '09 at 18:42
  • Well the main thing I saw was "ActeursDuProjet[item["Rôle"].ToString()]". What collection is this modifying (it looks like it is storing it in something called ActeursDuProjet which is the same name as your class)? – Kit Menke Jul 09 '09 at 21:20
  • I make a mistake my dictionary is named Acteurs the definition : Public IDictionary cobj_ActeursDuProjet = new Dictionary(); I use this dictonary to store this list : http://img53.imageshack.us/img53/1817/problemesharepoint.jpg I want to store the loginname ( for asignedto properties of tasks) and the email of the user who is in the first field of the list. – LoKtO Jul 10 '09 at 08:13