Question

I have a working alfresco share action defined in a share-config xml file like so:

<action id="myAction" type="link" label="sv.menu.label" icon="my-icon">
    <evaluator>my.custom.evaluator</evaluator>
    <param name="itemKind">action</param>
    <param name="itemId">scanvelopAction</param>
    <param name="href">/myapp/prefilled?prop1={node.properties.custom_prop}&amp;prop2={node.properties.custom_prop2}</param>
    <param name="target">_blank</param>
</action>

This works fine. As soon as the action link is clicked, it calls the defined url with the properties inserted.

Now, I'd like to add the username of the currently active user that's clicking the action link. To that end, I added:

&amp;u={person.properties.userName}

I've also tried, according to the ScriptNode API, {person.properties.name} and simply {person.name}.

The action continues to work as before, but only prints the new input as literal into the URL, as if this property is not defined (so I guess it isn't). I've tried variations of the above, but the result remains unchanged. I could find simply no documentation on the ScriptNode API's person-specific properties at all, and the examples I have found I've tried without success (see above).

How would I be able to achieve this?

Edit

I've also tried variations of user.name and user.userName.

Was it helpful?

Solution 2

The spring configuration wires on the server, and I'm guessing user info cannot be derived from anything configured there. Therefore, I solved this using a custom javascript action handler.

First off, I wired in my custom javascript in share-config-custom.xml like so:

<config>
    <forms>
        <dependencies>
            <js src="/components/documentlibrary/my-actions.js" />
        </dependencies>
    </forms>
</config>

In this javascript file, I defined a javascript function for action handling:

/**
 * Call a given url like an action of type 'link' would, but allows for configuration of the window.open call and 
 * appends the username of the active user in share to the url.
 * 
 * Uses the 'href' param to form the URL, and allows for the 'name' and 'specs' param.
 * 
 * @method onMyUserActionLink
 * @param record {object} Object literal representing one file or folder to be actioned
 * @param owner
 */
onMyUserActionLink : function dlA_onMyUserActionLink(record, owner) {
    Alfresco.logger.debug("onMyUserActionLink");
    var scope = this, nodeRef = record.nodeRef, jsNode = record.jsNode;
    Alfresco.logger.debug("Scope formed");

    // Get action & params
    var params = this.getAction(record, owner).params;
    Alfresco.logger.debug("Params retrieved");

    // Get URL
    var url = params.href;
    Alfresco.logger.debug("URL: " + url);

    // Append username
    var appendage;
    if(url.contains("?")) {
        appendage = "&u="+Alfresco.constants.USERNAME;
    } else {
        appendage = "?u="+Alfresco.constants.USERNAME;
    }
    url += appendage;

    Alfresco.logger.debug("URL+u: "+url);

    // Check for name
    var name = "_blank";
    if(params["name"]) {
        name = params["name"];
    }
    Alfresco.logger.debug("Name: "+name);

    // Check for specs
    var specs = "channelmode=yes,directories=no,fullscreen=yes,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,titlebar=yes,toolbar=yes,top=0,left=0";
    if(params["specs"]) {
        specs = params["specs"];
    }
    Alfresco.logger.debug("specs: "+specs);
    Alfresco.logger.debug("Opening window with url: "+url +", specs: "+specs+", name: "+name);
    window.open(url, name, specs);
}

I then registered the handlers for several Action contexts:

(function() {

    if (Alfresco.DocumentList) {
        YAHOO.lang.augmentProto(Alfresco.DocumentList, MY.doclib.FolderActions);
    }

    if (Alfresco.DocListToolbar) {
        YAHOO.lang.augmentProto(Alfresco.DocListToolbar, MY.doclib.FolderActions);
    }

    if (Alfresco.DocumentActions) {
        YAHOO.lang.augmentProto(Alfresco.DocumentActions, MY.doclib.FolderActions);
    }

    if (Alfresco.FolderActions) {
        YAHOO.lang.augmentProto(Alfresco.FolderActions, MY.doclib.FolderActions);
    }

    if (Alfresco.doclib.Actions) {
        YAHOO.lang.augmentProto(Alfresco.doclib.Actions, MY.doclib.FolderActions);
    }

    if (Alfresco.doclib.FolderActions) {
        YAHOO.lang.augmentProto(Alfresco.doclib.FolderActions, MY.doclib.FolderActions);
    }

})();

I changed my action bean configuration to work with this accordingly in share-config-custom.xml:

<action id="myaction" type="javascript" label="actions.mine.menu.label" icon="my-icon">
    <param name="function">onMyUserActionLink</param>
    <param name="itemKind">action</param>
    <param name="itemId">myAction</param>
    <param name="mode">create</param>
    <param name="destination">{node.nodeRef}</param>
    <param name="successMessage">actions.mine.success</param>
    <param name="failureMessage">actions.mine.fail</param>
    <param name="href">/mylink/linky?id={node.properties.my_idProp}&amp;prop2={node.properties.my_prop2}</param>
    <param name="name">_blank</param>
    <evaluator>evaluator.oa.action.isWhatIWant</evaluator>
</action>

The action calls my custom javascript, which appends the username, then proceeds to work as a link.

Shame even alfresco employees weren't able to respond to this, but I sure hope with the current lack of share client javascript on the internet this will help a good deal of developers!

TIP: For example bean configurations, look at share\WEB-INF\classes\alfresco\share-documentlibrary-config.xml. For example javascript, look at share\js\documentlibrary-actions.js.

OTHER TIPS

I'm not sure you can do exactly as you're trying to (I have also looked for the share-config root-scoped objects). The 'magic' action objects are hooked up some where hardcoded more or less (anybody know where?).

you can get the current user in Share/Surf server-javaScript by using the root-scoped object: 'user' OR by using the repository root-scoped object: 'person' in repository server-javascript

In repository Java use the AuthentificationUtils.

So you normally do not need to pass the currently logged in user to webscripts, they already know!

On the share client-side your normally have the value: Alfresco.constants.USERNAME

So everywhere your really executing, you have it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top