I have created two list. One is "Storage" the other is "Approvers"

I am able to retrieve all values in the column 'System' in the "Storage" list by iterating through the column list, like so and placing into a global var.

        using (SPSite siteCol = new SPSite("http://dev.portal.net/it/dev"))
            using (SPWeb web = siteCol.OpenWeb())                                                  
                //Get Storage list 
                SPList list = web.Lists["Storage"];

                //Iterate through the items in the list
                foreach (SPListItem item in list.Items)
                    //pick out your information needed                                              
                    GlobalWorkflowVar.var = item["System"].ToString();                        

Next, I get the "Approvers" list and query that list to retrieve the results.

                using (SPSite siteCol2 = new SPSite("http://dev.portal.net/it/dev"))
                    using (SPWeb web2 = siteCol2.OpenWeb())

                        SPList groupList = web2.Lists["Approvers"];

                        //Write SPQuery/CAML query
                        SPQuery myquery = new SPQuery();
                        myquery.Query =
                            //"<Query>" +
                            "<Where>" +
                                    "<Contains>" +
                                        "<FieldRef Name='Group' />" + "<Value Type='Text'>PO</Value>" +
                                    "</Contains>" +

I need to use the global variable so when the variable and query parameters are met, I can send out an email to the appropriate SharePoint Group I defined in the "Approver" list. How would I need to place the variable in the CAML query to retrieve the correct list items. The 'System' column within the "Approver" list has similar values to the 'System' column in the "Storage" list where I am getting the global var.


"Storage" List - 'System' column - Email (value)

"Approver" List - 'System' column - Email (value)

1 Answer 1

myquery.Query =
    "<Where>" +
        "<And>" +
            "<Contains>" +
                "<FieldRef Name='Group' />" +
                "<Value Type='Text'>PO</Value>" +
            "</Contains>" +
            "<Eq>" +
                "<FieldRef Name='System' />" +
                "<Value Type='Text'>" + GlobalWorkflowVar.var.ToString() + "</Value>" +
            "</Eq>" +
        "</And>" +

I think this is what you are asking? The type for the value of the "System" FieldRef may be off depending on how your list is set up.

To send the email, you can use the SPUtility.SendEmail() method.

See: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.sendemail.aspx

This may also help: http://davesquared.net/2007/07/sending-email-to-group-with-sharepoint.html

  • Okay, I get what you are saying. Is there a way to get the "currentitem" that the workflow instance is running on? By doing this, I can set the variable to that one item to query off of. I was able to retrieve one item only by using the ID, but you have to know the ID before running the WF
    – nholloway4
    Jul 30, 2012 at 16:30
  • In my Approver list. I have three columns which are: System, Group, and Approver which has the (Sharepoint Group) I want the email to be routed to. This is in a state machine WF task email, so I'm wondering if the createTask_TaskProperties.AssignedTo property where you send it to the group will be different.
    – nholloway4
    Jul 30, 2012 at 16:35
  • To get the base item, try OnWorkflowActivated.WorkflowProperties.Item msdn.microsoft.com/en-us/library/… msdn.microsoft.com/en-us/library/… Jul 30, 2012 at 16:37
  • Will do. Using this will kickoff the WF to the last item added? SO, I can get rid of this dreaded foreach statement then....lol
    – nholloway4
    Jul 30, 2012 at 16:45
  • Actually, I was able to retrieve the value using the Query you provided after checking the XML. Now, I just have to make sure it goes to the SharePoint Group selected in my list.
    – nholloway4
    Jul 30, 2012 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.