Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cmdlet to delete default user pinned views #22

Open
seanmcne opened this issue Dec 9, 2015 · 2 comments
Open

Add cmdlet to delete default user pinned views #22

seanmcne opened this issue Dec 9, 2015 · 2 comments
Assignees

Comments

@seanmcne
Copy link
Owner

seanmcne commented Dec 9, 2015

, ignore anything else that isn't grid views.

image

@seanmcne seanmcne self-assigned this Dec 14, 2015
@seanmcne
Copy link
Owner Author

Need to validate supportability & overall impact - that said user default is empty and there is no ability to unpin a view that is non-standard (if a user does it by accident, testing, etc). Changing these settings will force the users cache to expire so doing this on a mass scale may not be advised. Approach I'm thinking of taking is:

  1. Get the xml
  2. parse into "DefaultGridView" records/collection (verify uniqueness by entityobjecttypecode)
  3. Execute deletion from there either by "all" or by a specific ETC #

@seanmcne
Copy link
Owner Author

seanmcne commented Apr 21, 2017

Clear-CrmUserPinnedViews

#this will clear all user pinned views (no matter what they have pinned) 
Update-CrmRecord -Id $systemUserId -EntityLogicalName usersettings @{"personalizationsettings"=""} 

Remove-CrmUserPinnedView

#this is an attempt to clear the views by entityid - which seems to fail in and of itself, but if you dump ALL of them first, then add the result back, that seems to work 

$etc = 4 #clear out the users Account pinned views entity (otc/etc 4)

$us = Get-CrmRecord -EntityLogicalName usersettings -Fields personalizationsettings -Id (Invoke-CrmWhoAmI).UserId  

$systemUserId = $us.ReturnProperty_Id
$settings=[xml]$us.personalizationsettings
$etc = 2
$node = $settings.DefaultGridViews.SelectSingleNode("//EntityTypeCode[.='$etc']")
if(!$node -ne $null){
    $node = $node.ParentNode
    $node.ParentNode.RemoveChild($node)
}

#Attempt 1 - Successful update - but it doesn't "take" without clearing first
Update-CrmRecord -Id $systemUserId -EntityLogicalName usersettings @{"personalizationsettings"=""} 
Update-CrmRecord -Id $systemUserId -EntityLogicalName usersettings @{"personalizationsettings"=$settings.InnerXml} 

#Attempt 2 also failed
$newSettings = New-Object Microsoft.Xrm.Sdk.Entity
$newSettings.Id = $systemUserId
$newSettings.LogicalName = "usersettings"
$newSettings.Attributes.Add("personalizationsettings",$settings.InnerXml)

$updateRequest = new-object Microsoft.Crm.Sdk.Messages.UpdateUserSettingsSystemUserRequest
$updateRequest.UserId = $systemUserId
$updateRequest.Settings=$newSettings

$conn.ExecuteCrmOrganizationRequest($updateRequest)

@seanmcne seanmcne added this to the 2.7 milestone Aug 8, 2017
@seanmcne seanmcne modified the milestones: 2.7, 2.8 Dec 15, 2017
@seanmcne seanmcne removed this from the 2.8 milestone Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant