Output parameters in sharepoint designer are not working
-
08-12-2019 - |
質問
Here is what I have
A custom activity with 2 in parameters and 2 out parameters.
The custom activity code works fine and in debugging mode the parameter is set.
I created some log activities, after the activity runs, to see if the output parameters are being set, but they are always empty.
I attached a screenshot and also the code
code of the customactivity
public partial class CreateDocumentLibrary : SequenceActivity {
public CreateDocumentLibrary() { InitializeComponent(); } public static DependencyProperty SiteUrlProperty = DependencyProperty.Register("SiteUrl",typeof(string), typeof(CreateDocumentLibrary), new PropertyMetadata("")); [DescriptionAttribute("Url of site where document library is to be created")] [BrowsableAttribute(true)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] [ValidationOption(ValidationOption.Optional)] public string SiteUrl { get { return ((string)(base.GetValue(SiteUrlProperty))); } set { base.SetValue(SiteUrlProperty, value); } } public static DependencyProperty DocumentLibraryNameProperty = DependencyProperty.Register("DocumentLibraryName",typeof(string), typeof(CreateDocumentLibrary), new PropertyMetadata("")); [DescriptionAttribute("Name for DocumentLibrary")] [BrowsableAttribute(true)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] [ValidationOption(ValidationOption.Optional)] public string DocumentLibraryName { get { return ((string)(base.GetValue(DocumentLibraryNameProperty))); } set { base.SetValue(DocumentLibraryNameProperty, value); } } public static DependencyProperty DocumentLibraryResultNameProperty = DependencyProperty.Register("DocumentLibraryResultName", typeof(string), typeof(CreateDocumentLibrary), new PropertyMetadata("")); [DescriptionAttribute("Result Name for DocumentLibrary")] [BrowsableAttribute(true)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] [ValidationOption(ValidationOption.Optional)] public string DocumentLibraryResultName { get { return ((string)(base.GetValue(DocumentLibraryResultNameProperty))); } set { base.SetValue(DocumentLibraryResultNameProperty, value); } } public static DependencyProperty DocumentLibraryLinkProperty = DependencyProperty.Register("DocumentLibraryLink", typeof(string), typeof(CreateDocumentLibrary), new PropertyMetadata("")); [DescriptionAttribute("Link for DocumentLibrary")] [BrowsableAttribute(true)] [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)] [ValidationOption(ValidationOption.Optional)] public string DocumentLibraryLink { get { return ((string)(base.GetValue(DocumentLibraryLinkProperty))); } set { base.SetValue(DocumentLibraryLinkProperty, value); } } protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { CreateDocLibrary(); return ActivityExecutionStatus.Closed; } /// <summary> /// Checks if the list exists in the spweb object /// </summary> /// <param name="docLibName">Document Library name</param> /// <param name="web">SPWeb</param> /// <returns>Returns true if it exists</returns> bool listExists(string docLibName, SPWeb web) { try { //if there is no list with such name, it will throw an exception return (web.Lists[docLibName] != null); } catch { return false; } } /// <summary> /// Creates a document library with the name passed /// </summary> private void CreateDocLibrary() { try { using (SPSite oSPSite = new SPSite(SiteUrl)) { using (SPWeb oSPWeb = oSPSite.RootWeb) { string docLibNameBase = DocumentLibraryName; string docLibNameTemp = docLibNameBase; int iCounter = 1; while (listExists(docLibNameTemp, oSPWeb)) { docLibNameTemp = docLibNameBase + "(" + iCounter.ToString() + ")"; iCounter++; } SPList oSPList = oSPWeb.Lists.TryGetList(docLibNameTemp); if (oSPList == null) { Guid ID = oSPWeb.Lists.Add(docLibNameTemp, docLibNameTemp, SPListTemplateType.DocumentLibrary); DocumentLibraryResultName = docLibNameTemp; oSPList = oSPWeb.Lists[ID]; DocumentLibraryLink = SPUtility.ConcatUrls(oSPWeb.Url, oSPList.Views["All Documents"].Url); oSPList.OnQuickLaunch = false; oSPList.Update(); } } } } catch (Exception) { throw; } } }
code of the actions.actions
<Action Name="Create Doc Library" ClassName="MyCompany.CustomActivities.CreateDocumentLibrary"
Assembly="MyCompany.CustomActivities, Version=1.0.0.0,Culture=neutral, PublicKeyToken=207090b9b3f674c8"
AppliesTo="all" Category="MyCompany custom activities">
<RuleDesigner Sentence="Create document library: %1 in site: %2. (Save link in: %3, save document library name in: %4)">
<FieldBind Field="DocumentLibraryName" Text="Document List Name" DesignerType="TextArea" Id="1"/>
<FieldBind Field="SiteUrl" Text="Url of base site" Id="2" DesignerType="TextArea"/>
<FieldBind Field="DocumentLibraryLink" Text="Link to the document library" Id="3" DesignerType="TextArea"/>
<FieldBind Field="DocumentLibraryResultName" Text="Result name of to the document library" Id="4" DesignerType="TextArea"/>
</RuleDesigner>
<Parameters>
<Parameter Name="DocumentLibraryName" Type="System.String, mscorlib" Direction="In" />
<Parameter Name="SiteUrl" Type="System.String, mscorlib" Direction="In" />
<Parameter Name="DocumentLibraryLink" Type="System.String, mscorlib" Direction="Out" />
<Parameter Name="DocumentLibraryResultName" Type="System.String, mscorlib" Direction="Out" />
</Parameters>
</Action>
解決
The problem is with your DesignerType
attributes in your ACTIONS files. Since you want to set these to variables you should switch these lines:
<FieldBind Field="DocumentLibraryLink" Text="Link to the document library" Id="3" DesignerType="TextArea"/>
<FieldBind Field="DocumentLibraryResultName" Text="Result name of to the document library" Id="4" DesignerType="TextArea"/>
To this:
<FieldBind Field="DocumentLibraryLink" Text="Link to the document library" Id="3" DesignerType="ParameterNames"/>
<FieldBind Field="DocumentLibraryResultName" Text="Result name of to the document library" Id="4" DesignerType="ParameterNames"/>
The key difference being that the DesignerType
has been set to ParameterNames
which allows you to specify which variable to save the output into.
Documentation: http://msdn.microsoft.com/en-us/library/bb897971(v=office.14).aspx