Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Calling REST endpoint from code editor

Avatar

Level 2

Hi,

We have a requirement to integrate AEM forms (v6.3) with salesforce. What I understand is there are 2 ways to do it

1. Create a Form data model using salesforce swagger file/URL (Adobe Experience Manager Help | Configuring DataSource with Salesforce in AEM Forms 6.3 and 6.4)​. The only problem with this approach is that there is swagger file/url is not available to us.

2. Call the Rest endpoints from the code editor. I am assuming this is an option. If so appreciate if there is any article/documentation available on the implementation?

Is there any other options available?

Thx,

Prabu

22 Replies

Avatar

Employee Advisor

You will have to create swagger file manually

calling the REST endpoint directly from the code editor with out creating form data model will not work as the REST endpoints use authentication

Avatar

Employee Advisor

Or you will have to create OSGI service which communicates with salesforce

but creating the swagger file and creating FDMis the easiest option

Avatar

Employee Advisor

Simply make an AJAX call like any GET/POST request, it would work.  check the sample here https://forums.adobe.com/thread/2637181

Avatar

Employee Advisor

how will you authenticate with this mechanism?

SFDC uses oAith 2.0

Avatar

Employee Advisor

The answer is in context to point2 "2. Call the Rest endpoints from the code editor. I am assuming this is an option. If so appreciate if there is any article/documentation available on the implementation?"

Avatar

Employee Advisor

Anyways, Using JSforce you can connect to salesforce even via Javascript. Though handling at server would also be a good idea.

Document - JSforce

Avatar

Level 2

Hi,

Thanks for the response. The above example works and i have also tried with OSGI component. I believe it is working, just waiting for some creds for salesforce connectivity.

We have also built a separate captcha component using 3rd party library. How do we integrate this into the submit action of the form? Meaning on click of Submit button the captcha should be validated before submission

Avatar

Employee Advisor

Why not use the google captcha- we have out Of the box integration with it

Avatar

Level 2

As a digital preference, out client has moved away from Google Recaptcha into a 3rd party captcha service. We have implementated as a separate captcha component and is working fine for few other usecases. However I am not sure how do we integrate into AEM forms? 

Avatar

Employee Advisor

Currently using your own captcha implementation in AEM forms is not supported

Avatar

Level 2

Thanks for the response. Just a wild thought, haven't thought through this in detail yet. Is there a possibility to fetch the values entered in the form into another component. I am just thinking if I can separate captcha form submission and forms into 2 different components in a page.

Alternatively if we use OOTB AEM forms component is it possible for that integration?

Avatar

Employee Advisor

If another component is in form, yes you can easily use the rule or code editor.

You can have a different panel with Captcha and forms component.

Avatar

Employee Advisor

Though I shared an initial response on the query if you can detail the requirement I would add more to it.

Avatar

Level 2

Thanks Mayank. Let me try to add in the details here. we have a requirement to add the user registration into salesforce. The form to capture user registration has the usuals (firstname, lastname, email etc) which needs to be posted into salesforce.  The form also displays a captcha (not google recaptcha but a 3rd party service to render captcha) that should be validated before the actual form submission. So three are 2 parts to this. (1) AEM forms integration with Salesforce (2) AEM forms integration with 3rd party Captcha.

For Reqt(1), I am fairly comfortable to go with OSGI/JS option (currently experimenting on it) but not sure on how to go about reqt(2) though. Based on your above response even if we are able to render the captcha inside the form in a separate panel, how do we tie this to the form submit

Let me know if you need more details, thx

Avatar

Employee Advisor

I was going to suggest to have tabbed navigation in which the next tab gets enabled once you have successfully filled the respective panel.  Now the third party captcha which you are trying to validate would have some callback function and based on the success and failure you enable/Disable the submit button.

Avatar

Level 2

thanks for the response mayank. Yes captcha callback function returns true/false based on user input. I am little lost on how to capture this input and tie it to the submit button?

Avatar

Employee Advisor

Do something like this on callback in code-editor:

if (object.value == "true") {

    submit.enabled = true;

}

Have the submit button disabled by default.

Avatar

Level 2

I tried to integrate this but looks like the form doesn't pick up or submit the generated inputs that are not originally part of the form. It is picking up the values from lets say a text box field or any other element available in the form builder but when we include a custom component like captcha in our case, the generated input (for eg captcha response) is being ignored during the form submission.

Any ideas on how to pickup the captcha response from the form?