SharePoint 2013 Workflow–Lookup Activities

In SharePoint 2013 Workflows werden einige Activities angeboten, die die ListenId benötigen. Im jeweiligen Property Feld kann eine Liste ausgewählt werden.

image

Der tatsächliche Eintrag im Prperty wird zu folgendem Sourcecode:

System.Guid.Parse("{$ListId:Lists/urlaubstage;}")

Der Platzhalter $ListId…. wird durch die tatsächliche ListenID ersetzt. So weit so gut. Nur leider funktioniert dies nur, wenn der Workflow als Sandboxed Solution ausgeliefert wird. In einer Farm Solution wird dieser Platzhalter nicht ersetzt. Wie zu erwarten ist, kann aus dem Text “{$ListId…..” kein Guid geparsed werden. Die entsprechendene Fehlermeldung sieht dann so aus:

RequestorId: 768cedc5-12d4-2419-33f9-ddc55553fe3c. Details: System.FormatException: Expected hex 0x in '{0}'. at System.Guid.GuidResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument) at System.Guid.TryParseGuidWithHexPrefix(String guidString, GuidResult& result) at System.Guid.TryParseGuid(String g, GuidStyles flags, GuidResult& result) at System.Guid.Parse(String input) at System.Activities.CodeActivity`1.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at …

Dies ist ein bekannter Bug und wird hoffentlich demnächst behoben. Da “Demnächst” wohl nicht ausreichend schnell ist, hier ein Workaround:

Jeder Workflow wird mittels Elements.xml –Datei ausgeliefert. In dieser können wir weitere Parameter ablegen. Diese Parameter können im Workflow mittels “GetConfigurationValue” ausgelesen werden.

1) Anpassung Elements.xml

In die Elements-Datei ist eine weitere Zeile einzufügen um ein Property anzulegen.

   1:   <Module Name="WFEins" Url="wfsvc/18bfe43f6db7420fa3b0b5999963262b">
   2:      <File Url="Workflow.xaml" Type="GhostableInLibrary" Path="WFEins\Workflow.xaml" DoGUIDFixUp="TRUE">
   3:        <Property Name="ContentType" Value="WorkflowServiceDefinition" />
   4:        <Property Name="isReusable" Value="true" />
   5:        <Property Name="RequiresInitiationForm" Value="False" />
   6:        <Property Name="RequiresAssociationForm" Value="False" />
   7:        <Property Name="WSPublishState" Value="3" />
   8:        <Property Name="WSDisplayName" Value="WFEins" />
   9:        <Property Name="WSDescription" Value="My 'WFEins' Workflow" />
  10:        <!-- If you change the name or Url of your custom initiation or association form, 
  11:             remember to update the corresponding property value (InitiationUrl or AssociationUrl) to match the new web relative url.
  12:        -->
  13:        <Property Name="RestrictToType" Value="List" />
  14:        <Property Name="RestrictToScope" Value="{$ListId:Lists/antrag;}" />
  15:      </File>
  16:      <File Url="WorkflowStartAssociation" Path="WFEins\WorkflowStartAssociation" Type="GhostableInLibrary">
  17:        <Property Name="WSDisplayName" Value="WFEins - Workflow Start" />
  18:        <Property Name="ContentType" Value="WorkflowServiceSubscription" />
  19:        <Property Name="WSPublishState" Value="3" />
  20:        <Property Name="WSEventType" Value="WorkflowStart" />
  21:        <Property Name="WSEnabled" Value="true" />
  22:        <Property Name="WSGUID" Value="a0f42f40-b453-4120-b205-981009dbc9d8" />
  23:        <Property Name="WSEventSourceGUID" Value="{$ListId:Lists/antrag;}" />
  24:        <Property Name="Microsoft.SharePoint.ActivationProperties.ListId" Value="{$ListId:Lists/antrag;}" />
  25:        <Property Name="HistoryListId" Value="{$ListId:Lists/WorkflowHistoryList;}" />
  26:        <Property Name="TaskListId" Value="{$ListId:Lists/WorkflowTaskList;}" />
  27:        <Property Name="UrlaubsListeId" Value="{$ListId:Lists/urlaubstage;}" />
  28:      </File>
  29:    </Module>

In diesem Beispiel ist es die Zeile 27. An dieser Stelle funktioniert das Ersetzen der ListId. Somit steht in der Konfiguration ein Property mit dem Namen “UrlaubsListeId” zur Verfügung.

2) Auslesen des Properties im Workflow

im Bereich “Runtime” steht die Activity “GetConfigurationValue” zur Verfügung:

 

image

Diese Activity kann die Propertywerte der Elements-Datei auslesen und in eine Variable speichern.

Die Konfiguration der Activity sieht so aus:

image

Name ist der in der Elementsdatei angegebene Name der Eigenschaft. Und Result ist eine String-Variable in die der  Wert geschrieben werden soll. (in meinen Beispiel “urlaubsTageListeId”).

Ab nun kann im Workflow der Ausdruck  Guid.Parse(urlaubsTageListeId) verwendet werden um den Guid der Liste zu erhalten.

Kommentare sind geschlossen