I’m trying to use form to create a page based on defined template and at the same time set value for class properties of the new page.
Here’s my code:
{{velocity}}
#if("$!request.docName" != '')
## Request for creating a new instance
#set($uin1 = $services.uin.getNext('InternalAuditReporting'))
#set($docName = "${request.docName}$uin1")
#set($targetDocName = "${request.spaceName}.${request.Project}.${docName}")
#set($reference = $services.model.createDocumentReference('Wiki', 'QualityManagement', 'InternalAuditReporting', ${request.Project}, ${docName}))
#set($document = $xwiki.getDocument($reference))
$document.set('Project', ${request.Project})
$document.set('ID', $uin1)
$document.save()
#if(!$xwiki.exists($targetDocName) && $xwiki.hasAccessLevel('edit', $xcontext.user, $targetDocName))
$response.sendRedirect($xwiki.getURL($targetDocName, 'edit', "template=${escapetool.url($request.template)}&parent=${escapetool.url($request.parent)}"))
## Stop processing, since we already sent a redirect.
#stop
#end
#end
= Create Report =
#if("$!targetDocName" != '' && $xwiki.exists($targetDocName))
{{warning}}The target document already exists. Please choose a different name, or [[view the existing document>>$targetDocName]]{{/warning}}
#elseif("$!targetDocName" != '')
{{warning}}You don't have permission to create that document{{/warning}}
#end
{{html}}
<form action="" id="newdoc" method="post">
<div>
<input type="hidden" name="parent" value="${doc.fullName}"/>
<input type="hidden" name="sheet" value="1"/>
<input type="hidden" name="template" value="QualityManagement.InternalAuditReporting.InternalAuditReportingTemplate"/>
<input type="hidden" name="spaceName" value="QualityManagement.InternalAuditReporting"/>
<input type="hidden" name="docName" value="InternalAuditChecklist"/>
<p>Title: <input type="text" name="Title" size="100" column="3"/></p>
<p>Type: <input type="text" name="Type" size="100"/></p>
<p>Project: <select name="Project">
<option value="2018-2019">2018-2019</option>
<option value="2017-2018">2017-2018</option>
</select></p>
<span class="buttonwrapper"><input type="submit" value="Create" class="button"/></span>
</div>
</form>
{{/html}}
{{/velocity}}
So far, When I click the button, it was able to go to the edit view of the new page. However, the properties are not set. Please help.