05-08-2020 02:21 AM
Hi,
I have created new action in multi-select of documentLibrary but I am unable to call my create-package.ftl by clicking on it.
Code for creating new action
<!-- Document Library config section -->
<config evaluator="string-compare" condition="DocumentLibrary">
<multi-select>
<action type="action-link" id="onActionCreatePackage" icon="document-copy-to" label="menu.selected-items.createPackage" />
</multi-select>
</config>
code of my create-package..get.desc.xml
<webscript>
<shortname>London Weather</shortname>
<description>Simple Surf Web Script fetching London weather information</description>
<family>Share</family>
<url>/supplierPortal/createPackage</url>
</webscript>
Kindly suggest how can I call this .get.desc.xml from my new custom action.
05-08-2020 05:56 AM
Hi,
You need to define onActionCreatePackage function in javascript file and from that you can call your repository webscript.
05-08-2020 07:10 AM
Thanks @sanjaybandhniya .
I tried writing function in action.js and able to call this function but facing issue while calling repository action.below is the code written in onActionCrateFucntion. If Possible can you please share some example of calling repo in action.js
onActionCreatePackage: function dlA__SendPackage(record)
{
var theurl;
theurl = "/alfresco/apiCallCreation";
json = remote.call(theurl);
}
05-08-2020 12:21 PM
Hi,
Below way you can call repository webscript.
.Bubbling.fire("registerAction", { actionName: "actionname", fn: function _anyFunction(selectedNodes) { this.modules.actions.genericAction({ success: { message: this.msg("message") }, failure: { message: this.msg("message") }, webscript: { name: "url", method: Alfresco.util.Ajax.POST }, config: { requestContentType: Alfresco.util.Ajax.JSON, dataObj: { nodeRefs: dataObj } } }) } });
You can use ajax also to get/send data to repository.
07-27-2020 11:40 PM
Hi Sanjay,
I have a similar problem with an action called from the multiple selection menu in Share (Alfresco 6.2). In your example, what is the format of "url" (in name? My webscript for testing with a fixed parameter works like this:
http://localhost:8180/share/proxy/alfresco/mywebscript?nodeRef=workspace://SpacesStore/f63a0c20-27b3-4830-b3a5-345d38a10c3f
it returns xml.
My js code is:
YAHOO.Bubbling.fire("registerAction", { actionName: "onActionWebscript", fn: function my_onActionWebscript(selectedNodes) { this.modules.actions.genericAction({ success: { message: this.msg("msg-success") }, failure: { message: this.msg("msg-failure") }, webscript: { name: "http://localhost:8180/share/proxy/alfresco/mywebscript?nodeRef=workspace://SpacesStore/f63a0c20-27b3-4830-b3a5-345d38a10c3f", method: Alfresco.util.Ajax.GET }, config: { requestContentType: Alfresco.util.Ajax.XML, params: { } } }) } });
I also tried it with just this part:
"mywebscript?nodeRef=workspace://SpacesStore/f63a0c20-27b3-4830-b3a5-345d38a10c3f"
It always shows me my failure message.
07-28-2020 11:46 PM
After examining many examples in different posts I managed to solve my problem. In case it helps someone in the future, here's what I did:
1) Web script description defined as GET with JSON as the default:
<webscript> <shortname>Extract image tags</shortname> <description>Extrct image tags</description> <url>/mywebscript?nodeRef={nodeRef}</url> <format default="json"></format> <authentication>user</authentication> </webscript>
2) ftl template like this:
{"Return" : { "Images processed" : "${images}", } }
3) Java controller like this:
..... String nodeRef = req.getParameter("nodeRef"); StoreRef storeRef = new StoreRef("workspace", "SpacesStore"); // split into individual node IDs (* is a regex meta character) String[] images = nodeRef.split("\\*"); int len = images.length; int i = 0; while (i < len) { NodeRef node = new NodeRef(storeRef, images[i]); ....... i =i + 1; } // construct model for response template to render Map<String, Object> model = new HashMap<String, Object>(); model.put("images", len); .......
4) js script custom-doclib-actions.js
(function () { YAHOO.Bubbling.fire("registerAction", { actionName: "onActionWebscript", fn: function my_onActionWebscript(selectedNodes) { var nodeIDs = ""; var ii = 0; for (var i=0, ii=selectedNodes.length ; i<ii ; i++){ nodeIDs = nodeIDs + "*" + selectedNodes[i].nodeRef.substring(24); } nodeIDs = nodeIDs.substring(1); this.modules.actions.genericAction({ success: { message: this.msg("msg-success") }, failure: { message: this.msg("msg-failure") }, webscript: { name: "mywebscript?nodeRef={nodeRef}", stem: Alfresco.constants.PROXY_URI, method: Alfresco.util.Ajax.GET, params: { nodeRef: nodeIDs } }, config: { requestContentType: Alfresco.util.Ajax.JSON } }) } }); })();
This worked for me. It may not be the best way though. I couldn't find any documentation to make it better.
08-04-2020 01:08 PM
I wrote a blog post on this to try to help others who may also wonder how to add custom actions to the Selected Items menu in Share. There is an accompanying source code project on GitHub as well.
Explore our Alfresco products with the links below. Use labels to filter content by product module.