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
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;
}
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.
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
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
Regards,
Mike
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
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.