Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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>" +
                            "</Where>";

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.

I.E

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

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

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted
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>" +
    "</Where>";

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

share|improve this answer
    
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 '12 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 '12 at 16:35
    
To get the base item, try OnWorkflowActivated.WorkflowProperties.Item msdn.microsoft.com/en-us/library/… msdn.microsoft.com/en-us/library/… –  RJ Cuthbertson Jul 30 '12 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 '12 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 '12 at 16:59
show 8 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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