Quantcast
Channel: unset the manager changes activity feed in SharePoint 2010 - SharePoint Stack Exchange
Viewing all articles
Browse latest Browse all 2

unset the manager changes activity feed in SharePoint 2010

$
0
0

We wanted to unset the manager changes activity feed for all the users are in the SharePoint 2010 farm, have used the below code

using System;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.Office.Server.ActivityFeed;

namespace MysiteActivityOFF
{
    class Program
    {
        static void Main(string[] args)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
           {
               string currentSite = "http://weburl";
               using (SPSite aSite = new SPSite(currentSite))
               {
                   SPServiceContext currentContext = SPServiceContext.GetContext(aSite);
                   UserProfileManager userProfMan = new UserProfileManager(currentContext);
                   ActivityType activityType = null;
                   string userName = Environment.UserDomainName + "\\" + Environment.UserName;
                   UserProfile currentUser = userProfMan.GetUserProfile(userName);
                   ActivityManager activityMan = new ActivityManager(currentUser, currentContext);
                   bool rights = activityMan.PrepareToAllowSchemaChanges();<br/>
                   if (rights)
                   {
                       try
                       {
                           activityType = activityMan.ActivityTypes["ManagerChange"];
                           activityType.IsPublished = false;
                           activityType.Commit();
                           activityType.Refresh(true);
                           Console.WriteLine("Manager change activity successfully disabled for user : " + currentUser.DisplayName);
                       }
                       catch (Exception ex)
                       {
                           Console.WriteLine(ex.StackTrace);
                       }
                   }
                   Console.ReadKey(true);
               }
           });
        }
    }
}

however it throws the below error:

ERROR :
=======
In the "activityType.Commit();" line the exception occurs at :

Message :
ActivityManager.ActivityFeedSchemaMapping Exception
Inner Exception :
Procedure or function activityFeed_UpdateActivityTypes has too many arguments specified. StackTrace :
at
Microsoft.Office.Server.ActivityFeed.ActivityFeedSchemaMapping.InsertOrUpdateOne(ActivityFeedSchemaMapping[] mapping, Object obj, String sproc, SqlSession sqlSession, Boolean isInsert)
at Microsoft.Office.Server.ActivityFeed.ActivityType.Commit()

Powershell:<br/>
$loginname = "domain\account";<br/>
$site = get-spsite https://url<br/>
$context = Get-SPServiceContext $site;<br/>
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);<br/>
$profile = $upm.GetUserProfile([string]$loginname);<br/>
$am = New-Object Microsoft.Office.Server.ActivityFeed.ActivityManager($profile, $context);<br/>
$am.PrepareToAllowSchemaChanges();<br/>
$mgrChange = $am.ActivityTypes["ManagerChange"];<br/>
$mgrChange.IsPublished = $false<br/>
$mgrChange.Commit()<br/>

Error:

Exception calling "Commit" with "0" argument(s): "ActivityManager.ActivityFeedSchemaMapping Exception" At line:1 char:18 + $mgrChange.Commit <<<< () + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

Update-2:

[void] [System.Reflection.Assembly]::LoadWithPartialName("System") 
$loginname = "domain\user"
$site = Get-SPSite "URL"

$context = Get-SPServiceContext $site;
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context);
$profile = $upm.GetUserProfile([string]$loginname);

$am = New-Object Microsoft.Office.Server.ActivityFeed.ActivityManager($profile, $context)
$apptList = New-Object System.Collections.Generic.List[Microsoft.Office.Server.ActivityFeed.ActivityPreferencePerType]

$am.ActivityTypes | ForEach-Object {
  $appt = New-Object Microsoft.Office.Server.ActivityFeed.ActivityPreferencePerType
  $appt.ActivityType = $_
  $appt.IsSet = $false
  $apptList.Add($appt)
}
$am.ActivityPreferences.SetActivityPreferencesPerType($apptList)
$am.ActivityPreferences.Commit()
$am.ActivityPreferences.Refresh()

Irrespective of the user, it updates the service account profile(on which logged into the server). what could be the issue?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images