Can we give dropdown constraints only for Share and not the repository?

cancel
Showing results for 
Search instead for 
Did you mean: 
sepgs2004
Established Member

Can we give dropdown constraints only for Share and not the repository?

Jump to solution

My environments: Alfresco 5.2.x and above community edition, Alfresco Maven SDK 3.x, custom modeling

Say, I have employees list from which we choose to set for a property value
I am putting this in the model as a constraint 

 

<constraints>
        <constraint name="mcus:employeeNamesList" type="LIST">
            <parameter name="allowedValues">
                <list>
                    <value></value>
                    <value>Alen Blafer</value>
                    <value>Alexandel Rebok</value>
                    <value>Syriax Publit</value>
                    <value>Hraser Havier</value>
                    <value>Zmboe Vonatoo</value>
              </list>
           </parameter>
        </constraint>

And then later, I use this in a property definition

<property name=mcus:Employee_Name">
  <title>Employee Name</title>
  <type>d:text</type>
  <mandatory>false</mandatory>
  <index enabled="true">
    <tokenised>false</tokenised>
    <facetable>true</facetable>
  </index>
  <constraints>
     <constraint ref="mcus:employeeNamesList" />
  </constraints>
</property>

The constraint is defined in the model itself. Now, tomorrow, the employee list changes for obvious reasons, I must redo the model. In which case, generating the AMP files again, uninstalling the old ones, and install the new ones. 
Would this minimal change be good and not affect the internal working of this custom model?

Alternatively, can we give this kind of ("often-changing") dropdown constraints, only for the share UI tier, and not in the repository model?

 

Gnanasekaran Sakthivel
1 Solution

Accepted Solutions
abhinavmishra14
Advanced

Re: Can we give dropdown constraints only for Share and not the repository?

Jump to solution

That may not be an option available OOTB. But there are workarounds. One of which i can think of is this approach:

1- Create a json/xml file and it under Data Dictionary/Employees folder, you can either create the "Employees" folder and then employees.json/employees.xml manually or bootstrap using space bootstrapping method. See this doc for details: https://docs.alfresco.com/5.2/concepts/dev-extensions-modules-bootstrapping-files-spaces-xml.html

Keeping it in repository will allow you to update the json/xml whenever needed and changes will be immediately available without making content model changes and without restarting your server.

2- In your json/xml file define a list of employees, e.g.:

{
  "Employees": [
    "Alen Blafer",
    "Alexandel Rebok",
    "Syriax Publit"
  ]
}

3- Create a webscript (by extending org.springframework.extensions.webscripts.DeclarativeWebScript) which will read the employees.json and return the array of json (array of employees as shown in above example) as model object.

4- Update your content model and remove the constraint declaration, you would be using the property as text field in the content model, but you will display the list of employees dropdown on share form with help of above mentioned json and webscript.

<property name="mcus:Employee_Name">
  <title>Employee Name</title>
  <type>d:text</type>
  <mandatory>false</mandatory>
  <index enabled="true">
    <tokenised>false</tokenised>
    <facetable>true</facetable>
  </index>
</property>

5- Create a custom field template for the employee name property, take reference from selectone.ftl and use it in share form config, e.g.

Check this doc as well: https://docs.alfresco.com/5.2/references/forms-reference.html

<field id="mcus:Employee_Name">
  <control
	template="/org/alfresco/components/form/controls/employees.ftl" />
</field>

In your custom template you will call the webscript developed in step 3 and use the json array to populate a dropdown list of employees, this will allow user to select the employee from the list and save the form. The value will be persisted as a text as usual as it works for constraints defined in content model.

Take a look at this thread on how to call a webscript from freemarker template: https://hub.alfresco.com/t5/alfresco-content-services-forum/how-to-restrict-visibility-of-some-metad...

You will call the webscript and populate the list e.g.:

<script type="text/javascript">//<![CDATA[
    var populateEmpList = function(res){
        var result = eval('(' + res.serverResponse.responseText + ')');
        // process the response to build select menu
    }

Alfresco.util.Ajax.jsonGet({
    url : Alfresco.constants.PROXY_URI + "/getEmployees",
    successCallback : {
        fn : populateEmpList,
        scope : this
    },
    failureCallback : {
        fn : function() {},
        scope : this
    }
});
//]]></script>
~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

2 Replies
abhinavmishra14
Advanced

Re: Can we give dropdown constraints only for Share and not the repository?

Jump to solution

That may not be an option available OOTB. But there are workarounds. One of which i can think of is this approach:

1- Create a json/xml file and it under Data Dictionary/Employees folder, you can either create the "Employees" folder and then employees.json/employees.xml manually or bootstrap using space bootstrapping method. See this doc for details: https://docs.alfresco.com/5.2/concepts/dev-extensions-modules-bootstrapping-files-spaces-xml.html

Keeping it in repository will allow you to update the json/xml whenever needed and changes will be immediately available without making content model changes and without restarting your server.

2- In your json/xml file define a list of employees, e.g.:

{
  "Employees": [
    "Alen Blafer",
    "Alexandel Rebok",
    "Syriax Publit"
  ]
}

3- Create a webscript (by extending org.springframework.extensions.webscripts.DeclarativeWebScript) which will read the employees.json and return the array of json (array of employees as shown in above example) as model object.

4- Update your content model and remove the constraint declaration, you would be using the property as text field in the content model, but you will display the list of employees dropdown on share form with help of above mentioned json and webscript.

<property name="mcus:Employee_Name">
  <title>Employee Name</title>
  <type>d:text</type>
  <mandatory>false</mandatory>
  <index enabled="true">
    <tokenised>false</tokenised>
    <facetable>true</facetable>
  </index>
</property>

5- Create a custom field template for the employee name property, take reference from selectone.ftl and use it in share form config, e.g.

Check this doc as well: https://docs.alfresco.com/5.2/references/forms-reference.html

<field id="mcus:Employee_Name">
  <control
	template="/org/alfresco/components/form/controls/employees.ftl" />
</field>

In your custom template you will call the webscript developed in step 3 and use the json array to populate a dropdown list of employees, this will allow user to select the employee from the list and save the form. The value will be persisted as a text as usual as it works for constraints defined in content model.

Take a look at this thread on how to call a webscript from freemarker template: https://hub.alfresco.com/t5/alfresco-content-services-forum/how-to-restrict-visibility-of-some-metad...

You will call the webscript and populate the list e.g.:

<script type="text/javascript">//<![CDATA[
    var populateEmpList = function(res){
        var result = eval('(' + res.serverResponse.responseText + ')');
        // process the response to build select menu
    }

Alfresco.util.Ajax.jsonGet({
    url : Alfresco.constants.PROXY_URI + "/getEmployees",
    successCallback : {
        fn : populateEmpList,
        scope : this
    },
    failureCallback : {
        fn : function() {},
        scope : this
    }
});
//]]></script>
~Abhinav
(ACSCE, AWS SAA, Azure Admin)
abhinavmishra14
Advanced

Re: Can we give dropdown constraints only for Share and not the repository?

Jump to solution

Glad it worked for you. good luck @sepgs2004 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)