cancel
Showing results for 
Search instead for 
Did you mean: 

What 'root objects' are available to an action webscript ?

annakan
Champ in-the-making
Champ in-the-making
I try to implement an action on the document list that would allow a user to "sign" a document, adding a time-stamp and its name to a dedicated read only property/metadata.

from this http://wiki.alfresco.com/wiki/3.4_JavaScript_API#ScriptContent_API we are supposed to have several "root objects" (ugly globals right  :lol: ?) available but few of them are really present when my action runs  :roll: .

Most notably missing are the person object where I expected to retrieve the current logged in user / session user from.
Likewise, companyhome is not there, userhome neither, person is missing, people.isAdmin() does not exists …..


So what is the real context of an action ?
Where can I find the REAL objects available to me on a webscript depending on the context it is called ?
Can I reach and bring the one I miss into the scope through calls ?
And more pragmatically how can I access the current logged in user data and credentials from a webscript invoked through an action (function runAction(p_params) on the server side , this.modules.actions.genericAction() call on the client side.

is there something I miss completely there ?

Thanks a lot.
2 REPLIES 2

annakan
Champ in-the-making
Champ in-the-making
It is getting even more weird so there must definitely be something obvious  I miss.

Here is my code
<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/action.lib.js">

/**
* ValiderSignerDocument action
*
* @method POST
*/


function runAction(p_params)
{
   var results = [];
   var files = p_params.files;
   var file, fileNode, result, nodeRef;
  
   logger.log("Valider document args.signataire :" + args.signataire);
   //logger.log("Valider document person:" + person);
  
   var signataire = args.signataire;
  
    if (!files || files.length == 0) {
       status.setCode(status.STATUS_BAD_REQUEST, "No files.");
       return; }
   
   for (file in files)  {
      nodeRef=files[file];
      logger.log("nodeRef : " + nodeRef);
      logger.log("nodeRef.toString(): " + nodeRef.toString());
      result =
         {
         nodeRef : nodeRef,
         id : file,
          action: "ValiderSignerDocument",
          success: false,
         };
      logger.log("nodeRef : " + nodeRef);
      logger.log("nodeRef.toString(): " + nodeRef.toString());
      //fileNode = search.findNode("workspace://SpacesStore/5f35beee-4a83-4f98-b6cc-923804def5ad");
      fileNode = search.findNode(nodeRef);
      if (fileNode === null){
         result.success = false;
      }
      else {
         today=new Date();
         signatureMessage = "USER VALIDATION :" + today.toLocaleString();
         // comment vérifier que cette propriété existe, est ce bien un tableau (car multiple)
         fileNode.properties["an:ceresian_ValidationsIntermediaires"].push(signatureMessage);
         fileNode.save();
         result.success = true;
         logger.log("Valider document success ? message :" + signatureMessage);
      };
     
      results.push(result);
   }
   return results;
}

/* Bootstrap action script */
main();

As I said previously line 24 "//logger.log("Valider document person:" + person);" when un-commented  does not work.

BUT
fileNode = search.findNode(nodeRef); does not work either, even has I successfully used it in another action invoker webscript.

Even stranger the hard-coded fileNode = search.findNode("workspace://SpacesStore/5f35beee-4a83-4f98-b6cc-923804def5ad"); does not work even though I know the nodeRef is valid.

The error is
17:07:53,125  ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 03200014 Wrapped Exception (with status template): 03200038 Failed to e
xecute script 'classpath*:alfresco/extension/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/validerdocument.post.json.js': 03200037 Failed to execute search: ID:workspace\://SpacesStore/4d83b828\-23d8\-460a\-950e\-c1a76930e20b
org.springframework.extensions.webscripts.WebScriptException: 03200014 Wrapped Exception (with status template): 03200038 Failed to execute script 'classpath*:alfresco/extension/templates/webscripts/org/alfresco/slingshot/documentlibrary/action/validerdocument.post.json.js': 03200037 Failed to execute search: ID:workspace\://SpacesStore/4d83b828\-23d8\-460a\-950e\-c1a76930e20b

this ID:workspace\://SpacesStore/4d83b828\-23d8\-460a\-950e\-c1a76930e20b looks strange and suspicious to me but I don't know if it is the error message formatting code that escapes characters strangely or it is really what the "search.findNode()" method got …

I am probably too tired to see something obvious but ….

annakan
Champ in-the-making
Champ in-the-making
In case is stirs something.

I reproduced completely the custom action example ("backup action") and low and behold it  works flawlessly AND I have access to the whole context.
So something is different in my action (either in the call from the client side OR on the sever side) to prevent proper context setting.
It seems to me that in the debugger the action jumps one more time in a function on the backup action than on mine and that the line number in the "stitched together" javascript file (after "inclusions") is different and I would expect, all other things being the same, that the function runAction(p_params) would be at the same place.

I'll further investigate, it should be something obvious but very few clues about it.

I can confirm this, the sequence is
Backup action ———————————————————-    MyAction
1 (first line) ———————————————————-  1 (first line)
488 main() ———————————————————–  488 main()
597 getSiteInputParams() —————————————–   not called
765 getAssetNode(p_RootNode, o_AssetsPath) —————— 765 getAssetNode(p_RootNode, o_AssetsPath)
726 getMultipleInputValues(param) ——————————– 726 getMultipleInputValues(param)
807 runAction(p_param) ——————————————– 808 runAction(p_param)