Thursday, 11 July 2013

SharePoint 2010 - People Picker that is showing the wrong user profile information

Hi again,

introduction to this issue:  Someone has updated information on their MySite but their details have not propagated through to the People Picker, or any list that shows User Information in it.

Why:  This is due to the User Information List, which is used to supply User Information to all the SharePoint functions that use it.  The User Information List only seems to get updated when a user is first introduced to a Site Collection.  Not even a full Profile Sync will fix it. (You can find the User Information List here: http://[rootsite]/_layouts/people.aspx?MembershipGroupId=0).  This issue has been documented before and done very nicely on Gary's blog here: http://blog.falchionconsulting.com/index.php/2011/12/updating-sharepoint-2010-user-information/

The difference is between Gary's blog post and mine, is that his shows how to get a script to iterate through every Web Application and update specific fields.  Where as I will be showing how to look for a specific field & update it manually.

HOW TO FIX USING POWERSHELL

First get the User ID of the person who is having the issue:

$user = Get-SPUser -Identity 'domain\username' -Web http://sharepointserver
$user.id

Then you need to navigate to the Users details in the User Information List using their user ID you just found.  This code will list all the fields for that user appearing in the User Information List

$web = Get-SPWeb http://SharePointServer
$list = $web.Lists["User Information List"]
$item = $list.GetItemById($user.id)
$list.fields | % {Write-Host "$($_.InternalName) = $($item[$_.InternalName])"}

Now you should have found the field causing the issue, so you can update it like this:

$item["FieldName"] = "  "
$item.SystemUpdate()

Done!  Because this is a manual way of searching for the right fields to update, you will need to do this for every Web Application.

Tuesday, 9 July 2013

Making a jQuery banner from scratch

Woah, hang on a minute...  You mean you want me to build my own jQuery solution from scratch!?  Why would I do that when there are so many pre-packaged jQuery solutions out there?

Good question, if you are only making something very simple, maybe you'd like to optimise the amount of code the browser has to execute, and the pre-packaged solution may have many more features than you need...  Ok, I'll admit that's a bit far fetched for me to use as my own excuse.  I had some spare time, and wanted to see how easy it was.

The answer, as always, is it depends.

I was migrating a website from the early 2000's to a SharePoint site and I just wanted to replace a simple flash banner that faded in/out images & animated text.  Great little project I thought.

Here's how:
First I made a simple HTML page with a div for every image and sentence I wanted to fade in and out.  and an id against every div, so that I could reference them in the jQuery.

<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" />
</head>
<body>
<div id="background">
<div id="sydney"><div id="busy">Busy Joint</div></div>
<div id="melbourne"><div id="cold">Cold Joint</div></div>
<div id="brisbane"><div id="small">Small Joint</div></div>
<div id="perth"><div id="exxy">Exxy Joint</div></div>
</div>
</body>

I used CSS to hide all div's by default using 'display: none'.  and of course, used CSS to set all the other look/feel goodies.

Now to start Querying the J (jQuerying... ahem.):

A few pointers.

  • All jQuery needs to be inside <script> tags
  • Anything inside the Document Ready Function will run when the page loads
  • If you wish to cycle your animation indefinitely, my favourite way is to put the animation inside it's own function, which calls itself on the last line of the function.
  • Whenever you want to do something to an item, you call it like this: $("#[css id]").[dosomething]()   So the jQuery Syntax is: $(selector).action() 

Here's the beginning of my jQuery, fading in my 'sydney' and 'busy' divs, then animating the 'busy' words and then fading them out again:

<script>    
$(document).ready(function(){  
  
    $("#sydney").fadeIn("slow");    
    $("#busy").fadeIn("slow");        
    $("#busy").animate({left:"150px"}, 700, function(){     
        $("#sydney").fadeOut("slow");    
        $("#busy").fadeOut("slow");  
    });

});
</script>

Notice on the animate step, I've called a function which runs the FadeOut steps.  This is because although jQuery runs step by step, it doesn't wait until one step is finished to run the next step unless you tell it to.  So what I'm saying here is, don't fade the suckers out until the animation has completed.

So I wanted to make the banner do this four times with different DIV's.  All you need to do is rinse and repeat really!  Yes I probably could have optimised the code even further, but this is a simplistic version in order to teach a beginner how it works:

<script>
$(document).ready(function(){


startAnimation();

function startAnimation(){    
    $("#sydney").fadeIn("slow");    
    $("#busy").fadeIn("slow");        
    $("#busy").animate({left:"150px"}, 700, function(){     
    $("#sydney").fadeOut("slow");    
    $("#busy").fadeOut("slow");  

    $("#melbourne").delay(1000).fadeIn("slow");    
    $("#cold").delay(1000).fadeIn("slow");        
    $("#cold").animate({right:"150px"}, 700, function(){     
    $("#melbourne").fadeOut("slow");    
    $("#cold").fadeOut("slow");  

    $("#brisbane").delay(1000).fadeIn("slow");    
    $("#small").delay(1000).fadeIn("slow");        
    $("#small").animate({left:"150px"}, 700, function(){     
    $("#brisbane").fadeOut("slow");    
    $("#small").fadeOut("slow");  

    $("#perth").delay(1000).fadeIn("slow");    
    $("#exxy").delay(1000).fadeIn("slow");        
    $("#exxy").animate({right:"150px"}, 700, function(){     
    $("#perth").fadeOut("slow");    
    $("#exxy").delay(1000).fadeOut("slow",startAnimation);  
    });
   });
 });
});
}
});
</script>

I added a little bit extra there..
  • Used the Delay Action to make the steps wait 1 second.
  • Inserted a function to run all the animations, so that I could get the function to call itself and run forever.
  • The animate settings is telling the CSS to move the div right and left.
Hopefully that's not too much info.  Comment if you have any questions.

Monday, 1 July 2013

Entertainment book - Melbourne CBD - 2012-2013

Go to 2 expensive restaurants that do 2-for-1 and you've already made back the money you paid for the book.

Oh wow, now you have 700 other tickets of varied usefulness that can save you cash.

I personally prefer just to use all the restaurant ones as they give you the most value for money and force me to go to new restaurants!