1

I would like a workflow to be triggered when a property in a user's profile is edited. Ideally this would be triggered by an edit done either by a user or through the User Profile Synchronization Service.

For example, we have an HR System that needs to be updated when someone's name changes. We would like the employee who's name changed to perform the edit in the profile in SharePoint and then, when the profile is edited, it would trigger a workflow that would send an email to the HR indivudal who performs the update. Again, ideally we would like this to be done if an update to the profile is done through profile sync too.

Is this possible?

3 Answers 3

1

I have not seen any approach that would enable you to connect a workflow to the User Profile Update directly. You could write a timer job that queried the User Profile Change log with a query for the fields in question and then trip an event from there.

0

I didn't worked with workflows a lot but I think you can do something like this,

  1. When User make changes to User Profile Data start a "Approval Workflow" and then update user properties in code manually and do what you want to do after,

Here's the code for workflow completed method,

 public override void WorkflowCompleted(SPWorkflowEventProperties properties)
    {
        base.WorkflowCompleted(properties);
        if (properties.CompletionType != SPWorkflowEventCompletionType.Completed) return; //only update the Leave days when the leave request get approved.
        SPSecurity.RunWithElevatedPrivileges(delegate
        {
            using (SPSite site = new SPSite(properties.WebUrl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPWorkflow wf = new SPWorkflow(web, properties.InstanceId);
                    UpdateUserProfile(wf.AuthorUser.LoginName); //update the initiator's profile
                }
            }
        }
    }

Update the user's prfile

    public void UpdateUserProfile(string userAccount) 
    { 
        string url = "http://sp.adventure.com"; //replace with your site collection
        using(SPSite site = new SPSite(url)){
            SPServiceContext sc = SPServiceContext.GetContext(site);
            UserProfileManager upm = new UserProfileManager(sc); //now you have the manager object
            UserProfile up = upm.GetUserProfile(userAccount); //for example, "adventuer\\jony"
            up["Leave"] = int.Parse(up["Leave"].ToString())-1; //you may want to check if the Leave is more than 0
            up.Commit();
        }
    }

Source : Approval Workflow to update User Profiles Details

Hope it helps :).

0

An other solution would be to override the edit profile page and add your code to the save button.

I've found it here

To do it, you'll have to create an other page and redirect the edit page.

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.