another technical blog...technically

Monday, December 8, 2014

Azure SPFarm Manager 1.1 released

You're asking yourself, why in the world, Varro is writing articles as fast as hell?
I got the flu and lots of drafts.
So here's a good new one, the new version of Azure SPFarm Manager.
Here's the changes.
  • No more BuildEnvironment.ps1 command, now it's named Build.ps1
  •  Deprovision.ps1 command: so now you can save you money deallocating and removing your VMs whenever you want (config are saved in the export folder)
  • Reprovision.ps1: so you can spend your money whenever you wake up your farm
  • No more Config.xml file needed: if you have more than one farm, you can create more config files (e.g.: development.xml, integration.xml), if you don't select an existing file, the old Config.xml would be used for you


Do you wanna more?
Mmm.. sorry thats'it for today.
Download the code from here

Howto to deal with workflow manager when it refuses to install

This is what happens when you come back from a vacancy week:
  • Your (personal) mobile phone rings (yep i don't have a enterprise one) and customer asks why workflow manager installer for SP2013 farm, literally, "doesn't work" 
  • You take tube and bus (with 30° C) to reach customer office
  • You skip launch to discover the problem
  • You came back to the office and you continue your work till late
  • You start thinking about opening a bar in Copacabana
As usual /mode joke off
Today i will talk about safest installation procedure of workflow manager on SP2013 farm. Customers, very often configure farm server doing stuffs as block incoming connections or setting locale in such strange ways.
This could cause Web Platform installer strange behaviours and mainly Service Bus installation failure with this error (which is related to Windows Fabric, a Service Bus dependency)
Error
When i tried to install Workflow Manager stuffs i got this error:
Event ID 11722 Product: Windows Fabric — Error 1722. There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action DoFabricSetup, location: C:Program FilesWindows abricbinFabricFabric.Code.1.0MSIHiddenAppLauncher.exe, command:FabricSetup /operation:install /gac
Like you can read on this blog post (a real life-saving one: http://blog.riccardocelesti.it/workflow-manager-setup-issue/) this is due to locale settings. Service Bus and its dependencies can be installed only with locale settings en-us, but the check will let you install this piece of sotware it's only on this registry key.

Solution
So i built this little script, which is helpful to install workflow manager flawlessy.
Write-Host "Getting sTimeFormat RegEx value ... " -NoNewLine;
$regVal =  Get-ItemProperty -Path "Microsoft.PowerShell.Core\Registry::HKEY_USERS\.DEFAULT\Control Panel\International" -Name "sTimeFormat"
Write-Host "DONE" -ForeGroundColor GREEN;

$oldFormat = $regVal.sTimeFormat;
Write-Host "Old time format was: $oldFormat" -BackgroundColor YELLOW -ForeGroundColor BLACK;

Write-Host "Setting sTimeFormat RegEx value ... " -NoNewLine;
Set-ItemProperty -Path "Microsoft.PowerShell.Core\Registry::HKEY_USERS\.DEFAULT\Control Panel\International" -Name "sTimeFormat" -value "h:mm:ss tt";
Write-Host "DONE" -ForeGroundColor GREEN;

Write-Host "Download web platform installer ... " -NoNewLine;
$source = "http://download.microsoft.com/download/7/0/4/704CEB4C-9F42-4962-A2B0-5C84B0682C7A/WebPlatformInstaller_amd64_en-US.msi";
$destination = "c:\WebPlatformInstaller_amd64_en-US.msi";
Invoke-WebRequest $source -OutFile $destination;
Write-Host "DONE" -ForeGroundColor GREEN;

Write-Host "Installing web platform installer ... " -NoNewLine;
Start-Process c:\WebPlatformInstaller_amd64_en-US.msi -Wait;
Write-Host "DONE" -ForeGroundColor GREEN;

Write-Host "Refreshing WebPI products ... " -NoNewLine;
Start-Process "C:\Program Files\Microsoft\Web Platform Installer\webpicmd" -ArgumentList '/offline','/Products:WorkflowManagerRefresh','/Path:c:/WorkflowManagerFiles' -Wait;
Write-Host "DONE" -ForeGroundColor GREEN;

Write-Host "Installing workflow manager software ... " -NoNewLine;
Start-Process "C:\Program Files\Microsoft\Web Platform Installer\WebpiCmd.exe" -ArgumentList '/Install','/Products:WorkflowManagerRefresh','/XML:c:/WorkflowManagerFiles/feeds/latest/webproductlist.xml' -Wait;
Write-Host "DONE" -ForeGroundColor GREEN;

Write-Host "Starting workflow manager configurator ... " -NoNewLine;
Start-Process "C:\Program Files\Workflow Manager\1.0\Microsoft.Workflow.Deployment.ConfigWizard.exe" -Wait;
Write-Host "DONE" -ForeGroundColor GREEN;

Write-Host "Resetting sTimeFormat RegEx value to $oldFormat ... " -NoNewLine;
Set-ItemProperty -Path "Microsoft.PowerShell.Core\Registry::HKEY_USERS\.DEFAULT\Control Panel\International" -Name "sTimeFormat" -value $oldFormat;
Write-Host "DONE" -ForeGroundColor GREEN;

Write-Host "Cleaning files ... " -NoNewLine;
Remove-Item $destination;
Remove-Item "c:/WorkflowManagerFiles";
Write-Host "DONE" -ForeGroundColor GREEN;

Read-Host "Press any key to exit";
It could be done better, for example using powershell also for workflow manager configuration, maybe i'll do something similat for Azure SPFarm Manager.
Once you run the script, at first the sTimeFormat will be forced in the registry key, so installation could proceed on any locale configured SharePoint farm.



At the end the original value will be restored.
 And that's all, you can also download the code from here. Enjoy.

A simple script to log to verbose mode

Hi, this will be a quick post, just to show you a little PowerShell script (yeah, lately i'm in love with PowerShell) could be very helpful during bug hunting sessions.
When you run the script, the log level is raised to Verbose and a new SPLog file is created for this verbose log.
When you press a key, the log level is resetted to the default one, and a new SPLog file is created, so the penultimate log file is the one you need to examine.
This is the script: enjoy
$ver = $host | select version
if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} 
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) 
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

Write-Host "Setting TraceSeverity and EventSeverity to Verbose"
Set-SPLogLevel -TraceSeverity Verbose -EventSeverity Verbose

Write-Host "Creating a new Log file"
New-SPLogFile

Read-Host "Press ENTER key to reset default log level"

Write-Host "Resetting TraceSeverity and EventSeverity"
clear-sploglevel

Write-Host "Creating a new Log file for resetted log"
new-splogfile

Read-Host "Press any key to exit ..."
Or maybe download it from here.
Share:

SharePoint 2013 workflow task related item field

Another day spent with SP2013 workflows.
Do you remember when you had a task on SP2010 and you could get the workflow related item easily?
Good, it was something like that
taskItem["WorkflowItemId"]
Today, the game has changed.
Let's see this task view screenshot, everything lets you think you only have to do something like this
taskItem[SPBuiltInFieldId.RelatedItems]
to get a SPListItem, unfortunally you have to do more than this.
This field contains a JSON string containing web, list and item id, so you have to adapt this field value in order to do some work from code behind...

RelatedItem is one of the new site column SP2013 available for developers and can be used for other purposes, not only in workflows; so i decided to write this little helper in VLibs which lets you to read/write this field easily from server side, since CSOM supports this field.
[Serializable]
public class RelatedItemFieldValue
{
 #region Properties
 public int ItemId { get; set; }
 public Guid WebId { get; set; }
 public Guid ListId { get; set; }
 #endregion
} 
Then using this helper you can read and update this field value.
Related item field value is not assigned to the field when the task is created, so pay attention using event receivers events ItemAdding and ItemAdded for related item field read, use ItemUpdated or ItemUpdating instead.
I wrote this little piece of code you can find in Example 08, which overwrites the task related field item with the first item of the workflow items list in a event receiver.
string jsonString = properties.ListItem[SPBuiltInFieldId.RelatedItems].ToString();
List relatedItems = RelatedItemFieldHelper.GetItems(jsonString);
RelatedItemFieldValue r = relatedItems[0];
SPList l = properties.Web.Lists.TryGetList("WorkflowsItemsList");
SPQuery query = new SPQuery();
query.RowLimit = 1;
query.Query = "";
SPListItem first = l.GetItems(query)[0];
int itemId = first.ID;
r.ItemId = itemId;

// Safety... never enough
this.EventFiringEnabled = false;
properties.ListItem[SPBuiltInFieldId.RelatedItems] = RelatedItemFieldHelper.GetItems(relatedItems);
properties.ListItem.SystemUpdate();
// Rollbacking safety setting
this.EventFiringEnabled = true;
And here's the demonstration i'm telling the truth :-)


 Even if i'm confident you know it, here's the link to VLibs code :-) .

Sunday, December 7, 2014

Get user in SharePoint 2013 workflows

Today i'll present you a resolution of a common question when dealing with SharePoint 2013 workflows:
How the hell i get the user login name from a type user field?
The answer should be straighforward, unfortunally it isn't: it depends from the user field xml parameters.
Site columns
It is possible to declare a user field in defferent ways, so, reusing Example 01 code, i have extended the workflow item content type, so i can make some tests with those three different fields:
  1. Approvers (Type = UserMulti): used for multiple users
  2. Type User - Mult False: used for single user
  3. Type User - Mult True: used for multiple users too
<Field
       ID="{c55e296e-e0bf-4574-b266-a421781b5081}"
       Name="Approvers"
       DisplayName="Approvers"
       Type="UserMulti"
       Required="FALSE"
       Group="VLibs SP2013 Examples site columns"
       EnforceUniqueValues="FALSE"
       UserSelectionMode="PeopleOnly"
       UserSelectionScope="0"
       Mult="TRUE"
       Sortable="FALSE"/> 
<Field
       ID="{C4AC8A6C-F65C-4BC1-BE36-F83919EE9886}"
       Name="ItemUser"
       DisplayName="Type User - Mult False"
       Type="User"
       Required="FALSE"
       Group="VLibs SP2013 Examples site columns"
       EnforceUniqueValues="FALSE"
       UserSelectionMode="PeopleOnly"
       UserSelectionScope="0"
       Mult="FALSE"
       Sortable="FALSE"
       Overwrite="TRUE"/> 
<Field
       ID="{9af230e5-cdff-40ac-ae13-f2a6928dd1d1}"
       Name="ItemUsers"
       DisplayName="Type User - Mult True"
       Type="User"
       Required="FALSE"
       Group="VLibs SP2013 Examples site columns"
       EnforceUniqueValues="FALSE"
       UserSelectionMode="PeopleOnly"
       UserSelectionScope="0"
       Mult="TRUE"
       Sortable="FALSE"
       Overwrite="TRUE"/>
Workflow
 I have created a stupid workflow (named stupid workflow for real) which prints fields value in history
i added this item to the list, launched the workflow
 
and this was the result

As you can see, for the first field i obtained a list of user id, for the second field a single id: those int numbers can be used to make a user lookup, but what about the third field?

Resolution
For this particular example you need a custom activity in order to read the field value from results property in a collection string object.
This custom activity needs as input value, the user field dynamic value, and a collection string variable to save che user ids.

  
Placing the activity and configuring the output was this.
To play with this workflow and custom activity, you have to download latest version of VLibs from here, and enable features 01, 07a and 07b. Have fun.

Me, myself and I

My Photo
I'm just another IT guy sharing his knowledge with all of you out there.
Wanna know more?