How to Pass Workflow Propert in Control-Parm to FT

2019-08-14 13:34发布

So for my project, we have some javascript code running as a rule within the Alfresco repository. So whenever a new document comes into a certain space, a new folder is dynamically created and that document is moved into that newly created space. Additionally, whenever a new folder is created, a property is updated like so for the document (expect caseID is actually a dynamically generated value based on a sequence in our database):

//Add caseID as a property of the folder
var props = new Array(1);
props["wf:caseIDNum"] = caseID;
var newAspect = newNewSpaceName.addAspect("wf:caseID",props);

However, now we want to be able to reference that newly created aspect/property during the course of our workflow in our share-workflow-form-config-.xml file so that it can be passed as a parameter to our control template. That is, currently we have:

<field id="wf:submitCode" label-id="workflow.field.outcome" set="actions">
                  <control template="/org/alfresco/components/form/controls/workflow/custom-activiti-transitions.ftl"/>
               </field>

But what we want is something like the below:

<field id="wf:submitCode" label-id="workflow.field.outcome" set="actions">
                  <control template="/org/alfresco/components/form/controls/workflow/custom-activiti-transitions.ftl">
                     <control-param name="caseID">wf:caseIDNum</control-param>
                  </control>
               </field>

So my question is, is that the proper syntax to pass a variable/property from the workflow model to the FTL file via the control param?

Edit (10/25/12) -

So based on the help given here, I tried to modify my ftl page like so...

custom-activiti-transitions.ftl:

<#assign caseID = "">
<#if field.control.params.caseID??>
    <#assign caseID = field.control.params.caseID>
<#else>
    <#assign caseID = null>
</#if>

<style type="text/css">

.button {
border: 1px solid #666;
background: #DCDCDC;
padding: 5px;
color: #333;
text-shadow: 1px 1px #fff;
-moz-border-radius: 5px;
-webkit-border-radius: 5px
border-radius: 5px;
cursor: pointer;
-moz-box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
-webkit-box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
box-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}
a.button:hover {
background: #bbb;
color: #000;
text-shadow: 1px 1px #eee;
}

a.button:active {
position: relative;
top: 1px;
left: 1px;
-moz-box-shadow: none;
-webkit-box-shadow: none;
box-shadow: none;
}

</style>

<a class="button" href="#" onClick="MyWindow=window.open('http://localhost:8080/alfresco/faces/jsp/custom/CodeSelector.jsp?caseID=${caseID}','My Window','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=600,height=300'); return false;" style="text-decoration:none" target="_blank"><span>Add Codes</span></a>

And in my share-workflow-form-config.xml, I changed any instance of:

<field id="wf:submitCode" label-id="workflow.field.outcome" set="actions">
 <control template="/org/alfresco/components/form/controls/workflow/custom-activiti-transitions.ftl">
 </control>
</field>

to...

<field id="wf:submitCode" label-id="workflow.field.outcome" set="actions">
 <control template="/org/alfresco/components/form/controls/workflow/custom-activiti-transitions.ftl">
  <control-param name="caseID">wf:caseIDNum</control-param>
 </control>
</field>

My problem is that in the share-workflow-form-config.xml where I specify the control-param, I can get it to pass in a hard coded value like "30". However, when I try to get the value of the workflow property like wf:caseIDNum, it returns the actual string in the parameter like:

http://localhost:8080/alfresco/faces/jsp/custom/CodeSelector.jsp?caseID=wfcaseIDNum

as opposed to the actual value for the property, i.e. "30".

Any ideas on what I could be doing wrong?

2条回答
萌系小妹纸
2楼-- · 2019-08-14 14:15

It all depends on how you implement the control template. The aspect, and its related property are a static entity, they don't get "created" on the folder, they get "applied" to it. On a side note, please be aware that aspects are NOT automatically inherited by children nodes of a folder.

That said, you can indeed specify wf:caseID as the caseID input parameter of the template, than within the FTL you can refer to such a property with

field.control.params.caseID

You will need to implement the logic to go and retrieve the provided property and render it on screen properly.

查看更多
ら.Afraid
3楼-- · 2019-08-14 14:17

It's exactly as skuro said and you're not doing this rightly.

Very simple your config is correct but your ftl lacks some logic.

Why will you first check on <#if field.control.params.caseID??> And then not assign it?

It should be:

<#if field.control.params.caseID??>
   <#assign caseID = field.control.params.caseID>
<#else>
   <#assign caseID = 1>
</#if>

There is no need of a context or args or something.

Take a look at the default ones like /org/alfresco/components/form/controls/textarea.ftl

----- UPDATE -----

So how can one access another field in this template. So we've got another field "wf:caseIDNum" and we want to access that one.

You could use the following hacky mechanism to get it

${form.fields["prop_" + caseID?replace(":","_")].value}

in the form.fields all the current form properties are stored.

BTW don't forget to show the "wf:caseIDNum" and the hidden.ftl template or else the property won't be populated in the fields object ;).

查看更多
登录 后发表回答