cancel
Showing results for 
Search instead for 
Did you mean: 

AlfrescoJsApi not working correctly

os_cerna
Champ on-the-rise
Champ on-the-rise

Hello,

I recently started using ADF, I'm building an app using my instalation of Alfresco ECM 5.2, I have created a page within the app using the tutorials provided here.

My problem is that, i want to display information about a site which is on my ECM platform, i can login succesfully to platform but when it comes to getting the site info i have this error:

and this is my component.ts:

The weird part is that, i try the query on postman and it gives me the site i'm looking for:

I will appreciate any kind of help in this matter,

Thanks in advance,

1 ACCEPTED ANSWER

dvuika
Star Collaborator
Star Collaborator

You already import 'AlfrescoApiService' that reduces the code, you may also want to use 'AlfrescoAuthenticationService' to perform the login.

Here's the snippet code for the component that works for me and retrieves the site data, I've created a new public site 'demo1':

Dropbox Paper 

View answer in original post

7 REPLIES 7

dvuika
Star Collaborator
Star Collaborator

You are losing the context of "this" when calling "promise.then(..)" with a "function" parameter. Try using the "fat arrow" syntax to allow TypeScript maintaining the context for you:

getSite(...).then(data => {

   if (data) {

      this.nombreSitio = "your value";

   }

});

os_cerna
Champ on-the-rise
Champ on-the-rise

Thanks, but now i have this:

as you see, it doesnt seem to catch the correct values.

Also i have these errors when i inspect the page, i dont know if they are related:

dvuika
Star Collaborator
Star Collaborator

Based on your initial screenshot - your async code is executed in parallel. You try to log in and get data at the same time within different promises.

You should be calling Alfresco JS Api methods after login promise is resolved, for example:

api.login('admin', 'admin').then(ticket => {

   sites.getSite(...).then(data => {

       ....

   });

});

os_cerna
Champ on-the-rise
Champ on-the-rise

Based on your advice i modified my component.ts, now its like this:

but it still not catching the correct values:

thanks

dvuika
Star Collaborator
Star Collaborator

You already import 'AlfrescoApiService' that reduces the code, you may also want to use 'AlfrescoAuthenticationService' to perform the login.

Here's the snippet code for the component that works for me and retrieves the site data, I've created a new public site 'demo1':

Dropbox Paper 

dvuika
Star Collaborator
Star Collaborator

Please note that the JSON payload that comes with the JS API call is wrapped into the "entry":

{"entry":{"role":"SiteManager","visibility":"PUBLIC","guid":"08918280-26ba-4e9a-a2a7-a31075184144","id":"demo1","title":"demo1"}}

So you might need binding your properties to the "data.entry.id"

os_cerna
Champ on-the-rise
Champ on-the-rise

It worked, thanks a lot