Pass params to a JavaScript

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2011 05:53 AM
Hi, I've this function that execute a script:
It works fine, but how can I do for pass some params to the scripts?
After the script will go to read the passed params like this:
CAN YOU HELP ME?
IS IT POSSIBLE?
THANK YOU
private String startWorkflow(Reference refUponWF) throws RepositoryFault, NumberFormatException, RemoteException, WebServiceException, Throwable { log.info("startWorkflow, entrato"); String toReturn = ""; try { String nomeScriptWF = "prova.js"; // return the reference to the script List<Reference> scriptSearchResults = RepositoryUtils.searchLucene("/Data Dictionaty", nomeScriptWF); if (scriptSearchResults.isEmpty()) { throw new Exception("Non posso eseguiro lo script perchè NON ho trovato nessuno script con nome [" + nomeScriptWF + "]"); } Reference script = scriptSearchResults.get(0); toReturn = ActionUtils.executeScript(refUponWF, script); log.info("startWorkflow, risultato " + toReturn); } catch (Throwable t) { log.error("startWorkflow, errore generico.", t); throw new Throwable("Errore generico. Class: " + t.getClass().getName() + " Message: " + t.getMessage()); } log.info("startWorkflow, uscito"); return toReturn; }
It works fine, but how can I do for pass some params to the scripts?
After the script will go to read the passed params like this:
var param = args["paramName"];
CAN YOU HELP ME?
IS IT POSSIBLE?
THANK YOU
Labels:
- Labels:
-
Archive
5 REPLIES 5

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2011 04:41 AM
When you create object org.alfresco.webservice.action.Action you can call method setParameters(namedValueArray) and pass in NamedValue[] parameters.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2011 11:27 AM
Hi, thank you for the response, I've try to do this:
and the script:
but I've a this error:
Can you help me?
Thank you
Map<String, String> parameters = new HashMap<String, String>(1);parameters.put("script-ref", Utils.getNodeRef(script));parameters.put("prova", "Passato da WS");ActionUtils.executeAction(refUponWF, "script", parameters);
and the script:
function main() { try { var nodeRef = args.prova; logger.log("Parametro —- " + nodeRef); var nodeRef1 = args["prova"]; logger.log("Parametro —- " + nodeRef1); return "OK"; } catch (e) { logger.log("Error durante l'esecuzione dello script " + e); return e; }}main();
but I've a this error:
Error durante l'esecuzione dello script ReferenceError: "args" is not defined.
Can you help me?
Thank you

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2011 04:01 AM
Try accessing parameter by the name you specified (without args).
Example:
Example:
logger.log("Parametro —- " + prova);

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2011 11:07 AM
Nothing to do, others suggestions.
Thank you
Thank you

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2013 08:13 AM
If trying to access a param in a script that has been executed the following should work:
var scriptAction = actions.create("script");
var jsNode = companyhome.childByNamePath("Data Dictionary/Scripts/testAction.js");
scriptAction.parameters["script-ref"] = jsNode;
scriptAction.parameters["testarg"] = "hello";
scriptAction.execute(jsNode);
Then in testAction.js you can do the following:
var result = action.parameters["testarg"];
logger.log(result);
This should work.
HTH
Rich Hart
Alfresco Certified Engineer
Ixxus.com
var scriptAction = actions.create("script");
var jsNode = companyhome.childByNamePath("Data Dictionary/Scripts/testAction.js");
scriptAction.parameters["script-ref"] = jsNode;
scriptAction.parameters["testarg"] = "hello";
scriptAction.execute(jsNode);
Then in testAction.js you can do the following:
var result = action.parameters["testarg"];
logger.log(result);
This should work.
HTH
Rich Hart
Alfresco Certified Engineer
Ixxus.com
