Last active
September 9, 2017 12:21
-
-
Save Dheer-Rajpoot/308a7eb1992a5adb532dc1a56ad9f009 to your computer and use it in GitHub Desktop.
WFFM upgrade issue | Radio List Field or Drop List Field is empty in Form Designer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="c#" Debug="true" Async="true" %> | |
<%@ Import Namespace="System" %> | |
<%@ Import Namespace="System.Collections.Generic" %> | |
<%@ Import Namespace="System.Web" %> | |
<%@ Import Namespace="System.Net" %> | |
<%@ Import Namespace="System.Configuration" %> | |
<%@ Import Namespace="System.IO" %> | |
<%@ Import Namespace="Sitecore.Data.Items" %> | |
<%@ Import Namespace="Sitecore.Links" %> | |
<script runat="server"> | |
protected string databasename; | |
protected string FormTemplateId="{FFB1DA32-2764-47DB-83B0-95B843546A7E}"; | |
protected int count = 1; | |
private void UpdateAllFieldsRecursively(Item parentItem) | |
{ | |
if (parentItem != null) | |
{ | |
using (new Sitecore.SecurityModel.SecurityDisabler()) | |
{ | |
foreach (Item childItem in parentItem.Children) | |
{ | |
if (childItem.TemplateID == Sitecore.Data.ID.Parse("{C9E1BF85-800A-4247-A3A3-C3F5DFBFD6AA}") && | |
(childItem["Field Link"] == "{C6D97C39-23B5-4B7E-AFC7-9F41795533C6}" || | |
childItem["Field Link"] == "{CDD533E2-918A-4BE3-A12F-83A8580363F7}" || | |
childItem["Field Link"] == "{0FAE4DE2-5C37-45A6-B474-9E3AB95FF452}" || | |
childItem["Field Link"] == "{E994EAE0-EDB0-4D89-B545-FEBEF07DD7CD}") && | |
!String.IsNullOrEmpty(childItem["Parameters"])) | |
{ | |
using (new EditContext(childItem)) | |
{ | |
childItem["Localized Parameters"] = childItem["Parameters"]; | |
} | |
Response.Write("<tr>" + "<td>" + count++ + "</td>" + "<td>" + childItem.Paths.FullPath + "</td>" + "<td>" + childItem.ID + "</td>" + "</tr>"); | |
} | |
if (childItem.HasChildren) | |
{ | |
UpdateAllFieldsRecursively(childItem); | |
} | |
} | |
} | |
} | |
} | |
protected void btn_Update_Click(object sender, EventArgs e) | |
{ | |
databasename=txtDatabase.Text; | |
Sitecore.Data.Database database = Sitecore.Configuration.Factory.GetDatabase(databasename); | |
if (database != null && !String.IsNullOrEmpty(FormTemplateId)) | |
{ | |
Item parentItem = database.GetItem(new Sitecore.Data.ID(FormTemplateId)); | |
Response.Write("<p>Updated items:</p> <table>"); | |
var items = GetReferrers(parentItem.ID.ToString()); | |
foreach (var item in items) | |
{ | |
UpdateAllFieldsRecursively(item); | |
} | |
Response.Write("</table>"); | |
} | |
} | |
public Item[] GetReferrers(string itemId) | |
{ | |
Item item = Sitecore.Data.Database.GetDatabase(databasename).GetItem(new Sitecore.Data.ID(itemId)); | |
// getting all linked Items that refer to the Item | |
ItemLink[] itemLinks = Sitecore.Globals.LinkDatabase.GetReferrers(item); | |
if (itemLinks == null) | |
{ | |
return null; | |
} | |
else | |
{ | |
ArrayList items = new ArrayList(itemLinks.Length); | |
foreach (ItemLink itemLink in itemLinks) | |
{ | |
// comparing the database name of the linked Item | |
if (itemLink.SourceDatabaseName == databasename) | |
{ | |
Item linkItem = Sitecore.Data.Database.GetDatabase(databasename).Items[itemLink.SourceItemID]; | |
if (linkItem != null && linkItem.TemplateID == Sitecore.Data.ID.Parse("{FFB1DA32-2764-47DB-83B0-95B843546A7E}")) | |
{ | |
items.Add(linkItem); | |
} | |
} | |
} | |
return (Item[])items.ToArray(typeof(Item)); | |
} | |
} | |
</script> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Sitecore.Support.75227</title> | |
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR"> | |
<meta content="C#" name="CODE_LANGUAGE"> | |
<meta content="JavaScript" name="vs_defaultClientScript"> | |
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> | |
<link href="/default.css" rel="stylesheet"> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
<%--Form Template Item Id: | |
<asp:TextBox ID="tbItem" Text="{FFB1DA32-2764-47DB-83B0-95B843546A7E}" Width="400" runat="server" /><br />--%> | |
Enter Database Name: <asp:TextBox ID="txtDatabase" Width="400" runat="server" /><br /> | |
<asp:Button ID="btn_Update" runat="server" OnClick="btn_Update_Click" Text="Update" /> | |
</div> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment