PRVS PRVS - 6 months ago 50
Javascript Question

Get filename of workflow with javascript - Alfresco

I'm trying to obtain a filename of the items of a workflow.

I try to make this:

var title;
Alfresco.util.Ajax.jsonGet(
{
url: Alfresco.constants.PROXY_URI_RELATIVE + "api/metadata?nodeRef=" + nodeRefContext + "&shortQNames=true" ,
successCallback:
{
fn: function(response)
{
if (response.json)
{
title=response.json.properties["cm:title"];
alert(title);
}
},
scope: this
},
failureCallback:
{
fn: function(response)
{
Alfresco.util.PopupManager.displayPrompt(
{
failureMessage: this.msg("message.failure")
});
},
scope: this
}
});


But gives me undefined in the alerts...

I try too with:

var nodeR = search.findNode(fileNodeRef);
alert(nodeR);


But


search is not defined


Any idea how to obtain a filename of the workflow? In the URL I only have the noderef.

JMR JMR
Answer

You have cm:title but for the name of the file you have to access to the cm:name.

Output:

{
   "nodeRef":"workspace://SpacesStore/3444dc43-4526-4790-a63d-3827f55f53de",
   "aspects":[
      "{http://www.alfresco.org/model/rendition/1.0}renditioned",
      "{http://www.alfresco.org/model/content/1.0}versionable",
      "{http://www.alfresco.org/model/content/1.0}titled",
      "{http://www.alfresco.org/model/content/1.0}auditable",
      "{http://www.alfresco.org/model/system/1.0}referenceable",
      "{http://www.alfresco.org/model/system/1.0}localized",
      "{http://www.alfresco.org/model/content/1.0}author",
      "{http://www.alfresco.org/model/content/1.0}thumbnailModification"
   ],
   "mimetype":"application/pdf",
   "type":"{http://www.alfresco.org/model/content/1.0}content",
   "properties":{
      "{http://www.alfresco.org/model/content/1.0}autoVersionOnUpdateProps":false,
      "{http://www.alfresco.org/model/content/1.0}created":"2016-02-01T11:25:43.926Z",
      "{http://www.alfresco.org/model/content/1.0}lastThumbnailModification":[
         "doclib:1454326175307"
      ],
      "{http://www.alfresco.org/model/content/1.0}creator":"admin",
      "{http://www.alfresco.org/model/system/1.0}node-uuid":"0a790a38-2ccd-4a69-ae2f-282ebd743c26",
      "{http://www.alfresco.org/model/content/1.0}name":"examplepdf1.pdf",
      "{http://www.alfresco.org/model/system/1.0}store-protocol":"workspace",
      "{http://www.alfresco.org/model/content/1.0}content":"contentUrl=store://2016/2/1/11/29/c58f779f-f071-4d23-92d2-f38cd9f51578.bin|mimetype=application/pdf|size=94301|encoding=UTF-8|locale=en_US_|id=510",
      "{http://www.alfresco.org/model/system/1.0}store-identifier":"SpacesStore",
      "{http://www.alfresco.org/model/system/1.0}node-dbid":1231,
      "{http://www.alfresco.org/model/system/1.0}locale":"en_US",
      "{http://www.alfresco.org/model/content/1.0}versionLabel":"1.1",
      "{http://www.alfresco.org/model/content/1.0}modifier":"admin",
      "{http://www.alfresco.org/model/content/1.0}modified":"2016-02-01T11:29:34.763Z",
      "{http://www.alfresco.org/model/content/1.0}autoVersion":true,
      "{http://www.alfresco.org/model/content/1.0}initialVersion":true
   }
}

You can see "examplepdf1.pdf" is the name of the file and the property is name instead of the title.

So, instead of this:

title=response.json.properties["cm:title"];

put this:

title=response.json.properties["cm:name"];