AlfrescoJsApi not working correctly

cancel
Showing results for 
Search instead for 
Did you mean: 
os_cerna
Active Member

AlfrescoJsApi not working correctly

Jump to solution

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 Solution

Accepted Solutions
dvuika
Alfresco Employee

Re: AlfrescoJsApi not working correctly

Jump to solution

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 solution in original post

7 Replies
dvuika
Alfresco Employee

Re: AlfrescoJsApi not working correctly

Jump to solution

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
Active Member

Re: AlfrescoJsApi not working correctly

Jump to solution

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
Alfresco Employee

Re: AlfrescoJsApi not working correctly

Jump to solution

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
Active Member

Re: AlfrescoJsApi not working correctly

Jump to solution

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

but it still not catching the correct values:

thanks

dvuika
Alfresco Employee

Re: AlfrescoJsApi not working correctly

Jump to solution

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
Alfresco Employee

Re: AlfrescoJsApi not working correctly

Jump to solution

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
Active Member

Re: AlfrescoJsApi not working correctly

Jump to solution

It worked, thanks a lot