cancel
Showing results for 
Search instead for 
Did you mean: 

Access Repository from Alfresco Share and change Property

irenailievska
Champ on-the-rise
Champ on-the-rise
I am trying to change one property from my custom content type by clicking on an custom UI Action. The thing is I have very little knowledge of JavaScript. I suppose I need to create a javaScript file in share and a web script and js files in Repo. I have no idea where to put them or how to call them. I have the following code in share-config-custom.xml

< config evaluator="string-compare" condition="DocLibActions">
        < actions>
            < action id="example-active-enable" type="javascript" label="Active" icon="folder-manage-permissions">
                < param name="function">onActionSimpleRepoAction</param>
                < permissions>
                    < permission allow="true">Write</permission>
                < /permissions>
                < param name="action">enable-active-flag</param>
                < param name="successMessage">message.active-flag.success</param>
                < param name="failureMessage">message.active-flag.failure</param>
                < evaluator>example.evaluator.doclib.action.notActive</evaluator>
            < /action>
            < action id="example-active-disable" type="javascript" label="Inactive"  icon="folder-manage-permissions">
                < param name="function">onActionSimpleRepoAction</param>
                < permissions>
                    < permission allow="true">Write</permission>
                < /permissions>
                < param name="action">disable-active-flag</param>
                < param name="successMessage">message.active-flag.success</param>
                < param name="failureMessage">message.active-flag.failure</param>
                < evaluator>example.evaluator.doclib.action.active</evaluator>
            < /action>
        < /actions>
        < actionGroups>
            < actionGroup id="folder-browse">
                < action index="510" id="example-active-enable" />
                < action index="520" id="example-active-disable" />               
            < /actionGroup>
        < /actionGroups>       
    < /config>

I followed the Jeff Potts tutorial on Custom Actions http://ecmarchitect.com/alfresco-developer-series-tutorials/actions/tutorial/tutorial.html but can not quite finish my objective by using only the one. The custom-context.xml contains

< bean id="set-active-flag" class="example.action.executer.SetActiveFlag" parent="action-executer">
    < property name="nodeService">
        < ref bean="NodeService" />
    < /property>
< /bean>

< bean id="enable-active-flag" class="example.action.executer.EnableWebFlag" parent="set-active-flag">
    < property name="publicAction">
        < value>false</value>
    < /property>
< /bean>
< bean id="disable-active-flag" class="example.action.executer.DisableWebFlag" parent="set-active-flag">
    < property name="publicAction">
        < value>false</value>
    < /property>
< /bean>
The example.action.executer.SetActiveFlag, example.action.executer.EnableWebFlag and example.action.executer.DisableWebFlag are the same as the ones from the tutorial. But I don`t need to add aspect as it is shown there - I need to change a property!
I need to change a property my:isActive from my custom model, but have no idea how to do this. Can somebody help Smiley Very Happy ? It would be very appreciated!
Thanks in advance.
5 REPLIES 5

kavilash23
Champ on-the-rise
Champ on-the-rise
A good starting point would be adding something like the following to your custom action java class;

static final String SEEDIM_MODEL_1_0_URI = "http://www.seedim.com.au/model/1.0";
//create a qname for your custom property
static final QName MY_ISACTIVE = QName.createQName(SEEDIM_MODEL_1_0_URI, "isActive");
//pass on the nodeRef being act upon, the qname of your custom property and the value you want to set.
nodeService.setProperty(nodeRef, MY_ISACTIVE, true);

By my custom action java class you mean the SetWebFlag class from the tutorial or another class that I should write?

kavilash23
Champ on-the-rise
Champ on-the-rise
Putting it in EnableWebFlag class would make more sense.

It underlines the nodeRef variable and says nodeRef cannot be resolved to a variable… I tried searching but can't find what is the problem?
This is the EnableWebFlag.java class

import company.model.myModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.cmr.repository.NodeService;

public class EnableWebFlag extends SetActiveFlag {
   protected NodeService nodeService;
   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      action.setParameterValue(SetEnableFlag.PARAM_ACTIVE, true);
      QName MY_ISACTIVE = QName.createQName(myModel.NAMESPACE_COMPANY_ACTIVE_CONTENT_MODEL, "isActive");
      //pass on the nodeRef being act upon, the qname of your custom property and the value you want to set.
      nodeService.setProperty(nodeRef, MY_ISACTIVE, true);
      super.executeImpl(action, actionedUponNodeRef);
   }
}

irenailievska
Champ on-the-rise
Champ on-the-rise
I needed to put actionedUponNodeRef instead of nodeRef Smiley Very Happy THANKS A LOT!!!
The two lines worked the miracle needed to complete the action Smiley Very Happy

QName MY_ISACTIVE = QName.createQName(myModel.NAMESPACE_COMPANY_ACTIVE_CONTENT_MODEL, "isActive");
//pass on the nodeRef being act upon, the qname of your custom property and the value you want to set.
nodeService.setProperty(actionedUponNodeRef, MY_ISACTIVE, true);

Thanks,
Irena