AutoPopulate fields with userdetails based on UniqueID field

by chakram at 2013-02-26 05:58:09

Hi,

I have a requirement in the SharePoint 2010 List containing the fields - Unique ID (People picker), FirstName(SingleLineofText), LastName(SingleLineofText) and so on.

Whenever the user fill in the "UniqueID" column, the fields (Firstname and Lastname) should be automatically populated based on the UniqueID.

I need the powershell script for the same

Thanks,
Chakradhar
by poshoholic at 2013-02-26 06:54:20
Something like this?
function New-User {
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Name
)
# First clean up the input (remove leading/trailing whitespace, plus replace any paired spaces with a single space)
$Name = $Name -replace '^\s+|\s+$' -replace '\s+',' '
# Now get the name parts
$NameParts = $Name -split '\s',2
# Finally return an object with the name, firstname, and lastname properties
New-Object -TypeName PSObject -Property @{
Name = $Name
FirstName = $NameParts[0]
LastName = $NameParts[1]
}
}

Here’s some output from that command:
PS C:> New-User ‘Kirk Munro’

Name LastName FirstName
---- -------- ---------
Kirk Munro Munro Kirk


PS C:> New-User ‘Miguel de Icaza’

Name LastName FirstName
---- -------- ---------
Miguel de Icaza de Icaza Miguel


PS C:> New-User ‘Joe’

Name LastName FirstName
---- -------- ---------
Joe Joe


PS C:> New-User ’ Too ManySpaces '

Name LastName FirstName
---- -------- ---------
Too ManySpaces ManySpaces Too
by chakram at 2013-02-26 23:02:41
Hi Kirk,

Yes, it is almost same, but i need to get the userid/uniqueid(PeoplePicker) from the list field and it should autopopulate the other fields first and last name based on this unique id, i have attached the screenshot of the requirement, kindly let me know if that is possible through powershell for teh SharePoint 2010 List.

[attachment=0]10.jpg[/attachment]

Thanks,
Chakradhar.
by poshoholic at 2013-02-27 07:16:55
Ah, I thought you were using SharePoint as an example, looking for a script to do that work. I get what you’re looking for now. I’m not a SharePoint guy, so to help you get the right assistance for this I’m going to copy the thread into the PowerShell and SharePoint forum. Someone over there should be able to help you.
by AlexBrassington at 2013-02-27 15:36:50
Can you achieve it using Calculated fields? I can’t remember if you can use a People Picker control as a source in a calculation. See here for Calculated Field Formulae: http://msdn.microsoft.com/en-gb/library … 14%29.aspx

I suspect PowerShell isn’t the right tool for the job here. PowerShell is great at doing admin tasks and batch processing but if you want to interact with the events inside a SharePoint form or the item creation process in a list then you’re way out of luck. That’s full on Visual Studio event reciever madness.
With PowerShell you’re either using a hack to run PowerShell commands from C# (Very possible but why bother if you’re already using Visual Studio) or you’re running a scheduled task to pick these up in which case you’ve just complicated your DR plans (bad!) and have a less than optimal system (lag between creating an item and the fields being populated). There is almost certainly a use case where PowerShell makes sense but I can’t think of it at the moment.

If you want something to work dynamically as the user fills in the form then you’re going to have to use InfoPath to create a custom ‘new’ form and replace the default one for that list.

Have a look at this and see if it’s any use: http://msdn.microsoft.com/en-us/library … 14%29.aspx
by AlexBrassington at 2013-02-27 15:39:42
I swear I just posted a reply to this. :frowning:

Short version: PowerShell probably isn’t right for this. You’ll need to either use a calculated field: http://msdn.microsoft.com/en-gb/library … 14%29.aspx or a custom InfoPath creation form: http://msdn.microsoft.com/en-us/library … 14%29.aspx to get that sort of dynamic behaviour. I’m not certain that either is possible, try the calculated fields approach first and fall back to InfoPath as a more cumbersome but more powerful alternative.
by AlexBrassington at 2013-02-27 15:43:53
Odd, i’ve lost two posts now. I blame the links…

Short short version: I don’t think PowerShell can do this and i’m certain it’s not the right way to approach it. You can update values in a list easily enough but not in a form before submission, I can think of a way to do it but only an idiot would actually use it so i’m keeping quiet on the details, suffice it to say that it would be a very bad idea.

For that sort of dynamic in form behaviour you should try using Calculated Columns (using the People picker as a source) or Custom Infopath Forms to replace the new form behaviour. To be honest I doubt the Calculated column option will work without significant hacking so the InfoPath option is my recommendation.
by ToddKlindt at 2013-02-27 18:02:34
I’m with Alex. I don’t know of a supported way to do this. Sorry. :frowning:

tk
by poshoholic at 2013-03-02 07:40:22
Alex,

Sorry that your posts didn’t show up earlier. The software we use sometimes puts posts into a moderation queue, and I didn’t notice them until just now. I’ve approved those posts so they are visible now (and I’m going to go see if I can turn on a notifier so that I can be notified when something is held in moderation).