Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Workflow code into a workflow activity

$
0
0

Hi everyone, first post here and beginning SP2010 developer.

I have been tasked within my company to do some proof of concept Sharepoint work as well as training material development. Part of the POC work requires me to be able to change a boolean that tracks if a project lead has submitted their weekly reports (this was implemented into the User Profile properties) and to reset that variable every week.

I have a timer implemented through SPD2010 already using the framework I found here (http://sharepointgypsy.blogspot.com/2011/01/sharepoint-designer-workflows-3.html) and I know it works as I have tested it over a few days with a pause time of a few minutes.

I also have been able to create a custom workflow within VS2010 that changes the boolean as needed. Where I'm having problems is with turning that custom workflow into a custom work action so I can implement it within SP for other workflows that are planned. Everything I have found thus far seems to indicate that I need Dependency Properties and the like even though I'm not pulling anything down or adding to the SP site.

Here's the code I'm trying to get into an action:

public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
        string m_propertyInternalName = "reportSubmitted";
        string userAccnt = "user";
        bool submit = false;

        private void codeActivity1_ExecuteCode(object sender, EventArgs e)
        {
            SPSecurity.CodeToRunElevated elevatedValueChange = new SPSecurity.CodeToRunElevated(valueChange);
            SPSecurity.RunWithElevatedPrivileges(elevatedValueChange);
        }

        public void valueChange()
        {
            try
            {
                using (SPSite site = new SPSite("url"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPServiceContext context1 = SPServiceContext.GetContext(site);

                        UserProfileManager upm = new UserProfileManager(context1);

                        if (upm.UserExists(userAccnt))
                        {
                            
                            UserProfile up = upm.GetUserProfile(userAccnt);
                            submit = (Boolean) up[m_propertyInternalName].
                                up[m_propertyInternalName].Value = false;
                           
                            up.Commit();
                        }
                    }
                }
            }
            catch (Exception errx)
            {
                System.Diagnostics.Debug.Write("Error: " + errx.ToString());
                //Console.WriteLine(errx);
            }
        }
Thanks for all your help!

Viewing all articles
Browse latest Browse all 11571

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>