Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Update:</h2> <p>I heard back from Ektron Support on this issue. It's not so much a "bug" per-se... It's more a case of this API class looking very similar to the ContentManager but not behaving like it. I expected that since it looked so similar to ContentManager and many of the other classes, I would be able to call <code>Add()</code> and it would just magically work. It turns out the solution is a little more complicated.</p> <p><strong>Adding a smartform is a two-step process: first <code>Add()</code>, then <code>Update()</code>.</strong></p> <p>The Add method doesn't set all of the fields and in fact passes in NULL for a few of the parameters on the stored procedure that creates the entry in <code>xml_collection_tbl</code>.</p> <p>The real fun comes in step 2. Basically, you start with the SmartForm's HTML -- the stuff you see when you're in the "Data Design" view for editing the smart form definition and you click that <code>&lt;&gt;</code> button ("HTML") at the bottom of the editor. You run that through a whole bunch of XSLTs that are burried in the WorkArea folder to construct the missing fields, and then you call update. Here's the code that worked for me:</p> <pre class="lang-cs prettyprint-override"><code>var sfManager = new SmartFormConfigurationManager(); var data = sfManager.GetItem(12); if (data == null) return; var sfcData = new SmartFormConfigurationData(); sfcData.Type = EkEnumeration.XmlConfigType.Content; sfcData.SmartformTitle = "SmartForm12 copy"; sfcData.SmartformDescription = "SmartForm12 copy"; sfcData.XmlSchema = ""; sfcData.PackageDisplayXslt = data.PackageDisplayXslt; sfcData.FieldList = data.FieldList; sfcData = sfManager.Add(sfcData); Response.Write("SmartForm added with id: " + sfcData.Id); var design = System.IO.File.ReadAllText(Server.MapPath("~/NewsArticleSmartForm.html")); var contentApi = new ContentAPI(); var schema = contentApi.TransformXsltPackage(design, Server.MapPath("~/WorkArea/ContentDesigner/DesignToSchema.xslt"), true); var fieldList = contentApi.TransformXsltPackage(design, Server.MapPath("~/WorkArea/ContentDesigner/DesignToFieldList.xslt"), true); var viewEntryXslt = contentApi.TransformXsltPackage(design, Server.MapPath("~/WorkArea/ContentDesigner/DesignToEntryXSLT.xslt"), true); var xsltArgs = new XsltArgumentList(); xsltArgs.AddParam("srcPath", "", "/WorkArea/ContentDesigner/"); var viewXsltSource = string.Concat("&lt;root&gt;", design, "&lt;ektdesignpackage_list&gt;", fieldList, "&lt;/ektdesignpackage_list&gt;&lt;/root&gt;"); var viewXslt = contentApi.XSLTransform(viewXsltSource, Server.MapPath("~/WorkArea/ContentDesigner/DesignToViewXSLT.xslt"), true, false, xsltArgs, false); var initialDocument = contentApi.TransformXsltPackage(design, Server.MapPath("~/WorkArea/ContentDesigner/PresentationToData.xslt"), true); var sbPackage = new StringBuilder("&lt;ektdesignpackage_forms&gt;&lt;ektdesignpackage_form&gt;&lt;ektdesignpackage_designs&gt;&lt;ektdesignpackage_design&gt;"); sbPackage.Append(design); sbPackage.Append("&lt;/ektdesignpackage_design&gt;&lt;/ektdesignpackage_designs&gt;&lt;ektdesignpackage_schemas&gt;&lt;ektdesignpackage_schema&gt;"); sbPackage.Append(schema); sbPackage.Append("&lt;/ektdesignpackage_schema&gt;&lt;/ektdesignpackage_schemas&gt;&lt;ektdesignpackage_lists&gt;&lt;ektdesignpackage_list&gt;"); sbPackage.Append(fieldList); sbPackage.Append("&lt;/ektdesignpackage_list&gt;&lt;/ektdesignpackage_lists&gt;&lt;ektdesignpackage_views&gt;&lt;ektdesignpackage_view&gt;"); sbPackage.Append(viewEntryXslt); sbPackage.Append("&lt;/ektdesignpackage_view&gt;&lt;ektdesignpackage_view&gt;"); sbPackage.Append(viewXslt); sbPackage.Append("&lt;/ektdesignpackage_view&gt;&lt;/ektdesignpackage_views&gt;&lt;ektdesignpackage_initialDocuments&gt;&lt;ektdesignpackage_initialDocument&gt;"); sbPackage.Append(initialDocument); sbPackage.Append("&lt;/ektdesignpackage_initialDocument&gt;&lt;/ektdesignpackage_initialDocuments&gt;&lt;/ektdesignpackage_form&gt;&lt;/ektdesignpackage_forms&gt;"); sfcData.PackageXslt = sbPackage.ToString(); sfcData.FieldList = fieldList; var baseFilename = "SmartForm" + sfcData.Id; var schemaFilename = "/" + baseFilename + "Schema.xsd"; var xsltFilename = "/" + baseFilename + "Xslt.xslt"; sfcData.XmlSchema = schemaFilename; // The file will be prefixed with /XmlFiles var unPackDisplayXslt = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;&lt;xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"&gt;&lt;xsl:output method=\"xml\" version=\"1.0\" encoding=\"UTF-8\" indent=\"yes\"/&gt;&lt;xsl:template match=\"/\"&gt;&lt;xsl:choose&gt;&lt;xsl:when test=\"ektdesignpackage_forms/ektdesignpackage_form[1]/ektdesignpackage_views/ektdesignpackage_view[2]\"&gt;&lt;xsl:copy-of select=\"ektdesignpackage_forms/ektdesignpackage_form[1]/ektdesignpackage_views/ektdesignpackage_view[2]/node()\"/&gt;&lt;/xsl:when&gt;&lt;xsl:otherwise&gt;&lt;xsl:copy-of select=\"ektdesignpackage_forms/ektdesignpackage_form[1]/ektdesignpackage_views/ektdesignpackage_view[1]/node()\"/&gt;&lt;/xsl:otherwise&gt;&lt;/xsl:choose&gt;&lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt;"; var displayXslt = contentApi.TransformXsltPackage(sbPackage.ToString(), unPackDisplayXslt, false); System.IO.File.WriteAllText(Server.MapPath("~/XmlFiles" + xsltFilename), displayXslt); sfcData.Xslt1 = xsltFilename; // The file will be prefixed with /XmlFiles sfcData.DefaultXslt = 1; sfManager.Update(sfcData); </code></pre> <p>I extracted the HTML for my existing smart form and saved in the root of my site as NewsArticleSmartForm.html. Here's what my file looked like:</p> <pre class="lang-html prettyprint-override"><code>&lt;p&gt;Author:&amp;#160;&lt;input type="text" name="Author" id="Author" ektdesignns_caption="Author" ektdesignns_name="Author" title="Author" ektdesignns_indexed="false" ektdesignns_nodetype="element" size="24" class="design_textfield" /&gt;&lt;/p&gt; &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;p&gt;Article Summary:&amp;#160;&lt;textarea name="Summary" id="Summary" ektdesignns_caption="Summary" ektdesignns_name="Summary" title="Summary" ektdesignns_indexed="false" ektdesignns_nodetype="element" cols="40" rows="3" class="design_textfield"&gt;&lt;/textarea&gt; &lt;/p&gt; &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;p&gt;Article Body:&lt;/p&gt; &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;ektdesignns_richarea id="Body" name="Body" ektdesignns_caption="Body" ektdesignns_name="Body" title="Body" ektdesignns_indexed="false" ektdesignns_nodetype="element"&gt;&amp;#160;&lt;/ektdesignns_richarea&gt; &lt;p&gt;&amp;#160;&lt;/p&gt; </code></pre> <p>Good luck!</p> <h3>Original Answer:</h3> <p>Creating a copy of a SmartForm configuration should be fairly straight-forward. The <code>SmartFormConfigurationData</code> object has a <code>Clone()</code> method on it which makes it really easy to create a copy of an existing SmartForm. I say "should be" because it doesn't work.</p> <p>I had an answer all typed out ready to post; I tried some code and it appeared to work. The new smartform was listed in the workarea, but when I clicked on that new smartform to view its details, I realized something was wrong.</p> <p>I tried the following code:</p> <pre class="lang-cs prettyprint-override"><code>var sfManager = new SmartFormConfigurationManager(); var config = sfManager.GetItem(7); if (config == null) return; var newSmartForm = config.Clone(); newSmartForm.SmartformTitle += " copy"; sfManager.Add(newSmartForm); </code></pre> <p>Here are the details from the original smartform: <img src="https://i.stack.imgur.com/2DYnV.jpg" alt="original smartform, properties tab"> <img src="https://i.stack.imgur.com/K7AM7.jpg" alt="original smartform, Display Information tab"></p> <p>And here's what the new smartform looked like -- the one I created with the frameworkAPI: <img src="https://i.stack.imgur.com/A1jUj.jpg" alt="api-generated smartform, properties tab"> <img src="https://i.stack.imgur.com/EeyOs.jpg" alt="api-generated smartform, Display Information tab"></p> <p>I did find one API method that successfully created a copy of an existing smartform:</p> <pre class="lang-cs prettyprint-override"><code>var sfApi = new Ektron.Cms.ContentAPI(); var newId = sfApi.ReplicateXmlConfiguration(7, "copied sf title"); </code></pre> <p>The problem with that method is that the smartform must exist on your system and you can only change the title. So, I went digging into the database to see what was happening. It turns out that after calling this <code>ReplicateXmlConfiguration()</code> method, the two database records are identical (except for the expected LastUpdated type of fields).</p> <p><img src="https://i.stack.imgur.com/fyEp2.jpg" alt="source and target database records after calling ReplicateXmlConfiguration()"></p> <p>After calling the frameworkAPI's <code>Update()</code> method (same holds true when calling <code>Add()</code>), the "updated" record is clearly different.</p> <p><img src="https://i.stack.imgur.com/y2HLV.jpg" alt="source and target database records after calling Update() in framework api"></p> <p>I think we've got a genuine bug here. This happens both in v8.7 sp2 and v9.0 sp1. I've opened a case with Ektron support, and I'll update my answer as I hear back. They have always been very responsive when I've dealt with them in the past.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload