How to get repo URL from Alfresco Javascript?

cancel
Showing results for 
Search instead for 
Did you mean: 
upforsin
Senior Member

How to get repo URL from Alfresco Javascript?

Hello,

Is there a way to receive a URL path for Alfresco repository from JavaScript (browser console) ?

I know I can get easily share URL by calling:

Alfresco.constants.PROXY_URI

But i did not find similar node for repo url..

Regards,

Mike

howkymike
Alfresco Developer
5 Replies
abhinavmishra14
Advanced

Re: How to get repo URL from Alfresco Javascript?

Not really sure but you can try: Alfresco.constants.URL_SERVICECONTEXT

If the purpose is to call repository webscript then you can do it using the below given approaches from share side webscript. 

//Call getUserInfo repository webscript.
var resp = remote.call("/getUserInfo"); //Call to connected alfresco repository, e.g. http://127.0.0.1:8080/alfresco/service/getUserInfo
if (resp.status == 200) {
  var obj = JSON.parse(resp.text);
  model.name= obj.name;
}

OR

// Call the repo 
var conn = remote.connect("alfresco"),
res = conn.get("/getUserInfo"),
json = JSON.parse(res);

if (json.data) {
  model.name = json.data.name;
}

or

var url = "/getUserInfo";
var result = remote.connect("alfresco").get(url);
if (result.status == 200)
{
  model.name = JSON.parse(result).name;
}

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
upforsin
Senior Member

Re: How to get repo URL from Alfresco Javascript?

Well, first of all, thank you for the response. But your code doesn't work in browser console so it won't work in the Freemarker template :/

My goal is to call custom repository Webscript from control in the task-edit in the Alfresco Share.

I didn't want to hard-code alfresco URL ("http://localhost:8080") in the .ftl file so I though it might be a function for it.

Unfortunately, now I see that there is a much bigger problem. Authentication in the Share in not enough for Repo. (i set up my web-script to "<authentication>user</authentication>").

Do you have any idea how can I "pass authentication" from Share to Repo?

Right now I'm getting 401 Unauthorized error.

I also tried using share Proxy ("http://localhost:8180/share/proxy/alfresco ") - no authorization problems this time but it does not always behave in the same way - it does return only a fraction of JSON with an empty JSONArray! It happens only while using share Proxy AND while not passing any URL parameters

Regards,

Mike

EDIT. It was an external server's fault. Alfresco Share adds additional parameter to URL (alf_ticket) and it disrupted server logic.

Sorry for trouble.

howkymike
Alfresco Developer
abhinavmishra14
Advanced

Re: How to get repo URL from Alfresco Javascript?

I am not clear what do you mean by browser console, i might have misunderstood but the code which i shared was for share side webscript (js) which can be used to call repository side webscript.

Also i am not sure why using Alfresco.constants.PROXY_URI is a problem for you to call repository custom webscript from javascript . 

To call repo webscript: Alfresco.constants.PROXY_URI can be used

To call share webscript: Alfresco.constants.URL_PAGECONTEXT can be used

~Abhinav
(ACSCE, AWS SAA, Azure Admin)
upforsin
Senior Member

Re: How to get repo URL from Alfresco Javascript?

Well,

My goal is to change Share control (like textview, editview, button etc.) in the Task-Edit page.

To achieve that I created custom Freemarker template. Inside, I included <script> tag from where I invoke Javascript code.

The code inside <script> tag behaves exactly the same as in the Browser's developer Console (i.e. Firefox's FireBug or Chrome's DevTools)

From your answer I understand that there is another way to include JavaScript code. But then, how can I connect JavaScript Controller/Share side web-script to the particular control(i.e. custom text-view)?

Also i am not sure why using Alfresco.constants.PROXY_URI is a problem for you to call repository custom webscript from javascript . 

It is no longer a problem. It was an external server's fault. My original problem has been solved Smiley Happy

Regards,

Mike

howkymike
Alfresco Developer
abbask01
Senior Member

Re: How to get repo URL from Alfresco Javascript?

You can use the share proxy URL of your webscripts goto http://<>:<>/share/service/index to find your extact url. All webscripts that you create on repo are also acessible from their roxy urls

Regards,
Abbas