How do the dropdown and typeahead fields make REST calls?

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

How do the dropdown and typeahead fields make REST calls?

How do the dropdown and typeahead fields make REST calls in Alfresco Process Services, and can users replicate that functionality in custom stencils? 

Also, is there a way to access Alfresco account information for linked Alfresco accounts in the process for custom REST calls? I know the Folder and File form field use this information in some capacity, so how do they access it? 

6 Replies
ryandawson
Alfresco Employee

Re: How do the dropdown and typeahead fields make REST calls?

Presumably part of what you want to do is to make a rest call and use the result in a subsequent step? If so these links may be of help:

Rest call task | Alfresco Documentation 

REST Call Task and People form variables in the request 

You can also choose an endpoint for a typeahead. There's a general rest integration guide in which this is mentioned:

https://community.alfresco.com/community/bpm/blog/2016/08/31/rest-integration-101 

As you can see from the links, the authentication for an endpoint is configured when you set it up.

As for the alfresco integration, I may be wrong but I don't think there is anything that lets a user be chosen at run-time. I'm only seeing examples where that gets decided at design-time (unless it is the process initiator). The file and folder controls use the authentication set up when the repository was configured in APS. A publish or action step will be carried out as a particular user or as the process initiator. If as a particular user then that is stored in the process definition (in the xml).

Could you elaborate on your particular use-case that you're trying to work through? Are you, for example, trying to show a drop-down that contains a list of users from an alfresco content repository?

jvaidya
Active Member II

Re: How do the dropdown and typeahead fields make REST calls?

Thanks for the detailed response, Ryan! I have a couple use cases, but a good example is a custom Alfresco folder selector with search and filter capabilities. I want to use Angular to write a custom form stencil with this field, and somehow call an Alfresco WebScript when the user opens the form. The WebScript will return a list of folders and the form field should use that list to display the folder tree to the user. I could use the Angular controller to perform the REST call, but that leads to CORS issues, and more importantly, the user's Alfresco credentials are not available (as far as I know). It would be ideal if I could get Alfresco credentials based off who is logged in, because that would allow me to authenticate API calls for each user instead of storing the authentication. The Folder form field does this, so I wanted to know if it was possible to replicate this functionality. 

I've played with REST Tasks before, but that's not exactly what I'm looking for because the user has to submit the form and open a new form to see the results. I'd like to have the REST call happen while the user is looking at the form, for example when a field comes into focus.

jvaidya
Active Member II

Re: How do the dropdown and typeahead fields make REST calls?

I just wanted to follow up on this question, Ryan. 

Are the user's Alfresco credentials available user side? We want to include REST tasks in our processes that use different authorization headers based on who the process initiator is. How can we do this? 


ryandawson
Alfresco Employee

Re: How do the dropdown and typeahead fields make REST calls?

I assume you're not just looking to get the alfresco credentials of the user that is currently logged in? I ask because that's the credentials that will be used by default anyway when using the built-in components. 

If you have an instance of APS available then you may want to go to the api-explorer.html page and look at the /rest/integration/alfresco endpoints. If the authentication you want isn't available from there then presumably you would need to get it yourself by implementing relevant classes and exposing your own endpoint. Something a bit like this has been done before - activiti-examples/activiti-ui-api-proxy at master · cijujoseph/activiti-examples · GitHub . In your case you'd be looking to get details out of APS itself so I think you'd be looking to use the AlfrescoOnPremService and/or UserAccountServiceImpl, if you have access to them.

I think it should be possible to work around CORS. See this page for Alfresco CMS - alfresco-ng2-components/ALFRESCOCORS.md at master · Alfresco/alfresco-ng2-components · GitHub and this for APS - Configuring CORS | Alfresco Documentation 

Actually that CORS page came from the ADF project - GitHub - Alfresco/alfresco-ng2-components: Alfresco Angular 2 components . You may want to look at the demos of the ADF components - Alfresco Angular 2 Components Catalog . If ADF is of interest you could try asking on the ADF gitter channel (linked to from the main ADF github readme).

jvaidya
Active Member II

Re: How do the dropdown and typeahead fields make REST calls?

We are looking for the credentials of the user that has logged in, but we wanted to write custom components to add new functionality. So we wanted to use the user's credentials in our API calls. 

I looked at the Alfresco endpoints in the API Explorer, and that's somewhat what we want to use, but we were hoping to use a custom WebScript on the Alfresco side for performance reasons. So ideally, we could call our own REST Endpoint using the credentials of the user who has logged in. 

ryandawson
Alfresco Employee

Re: How do the dropdown and typeahead fields make REST calls?

Actually maybe all you need is SSO? Perhaps you could consider using Oath2 (OAuth 2 SSO overview | Alfresco Documentation ) or as of 1.6.3 we aim to add a feature for kerberos. I think that release is due this week.