Expand my Community achievements bar.

custom action on AEM form

Avatar

Level 6

Hi Team,

 

I have created simple form it contains 4 fields like 

 

First Name

Last Name

DOB

Gender

 

After submitting i need to call servlet to send this to some other system.

 

How i can send these data to my custom servlet 

I have created my path based servlet and path is /bin/aem/customerdata

 

Can some one help me here 

 

7 Replies

Avatar

Employee Advisor

@manikanthar1295 

You can post the data to the sling servlet's doPost method using the JQuery AJAX request.

 

     $.ajax({
        type: 'POST',
        url:'/bin/myServlet',
        data:{'First Name' : val1,'Last Name' : val2},          //passing values to servlet
        success: function(msg){
            //Success logic
        }
    });

Hope this helps!

Avatar

Level 6

@Pulkit_Jain_ 

 

Thanks for your reply.

 

I am using the adaptive form  which contains 4 fields

First Name

Last Name

DOB

Gender

 

Can i use same $ajax call in Adaptive form as well.

if yes where i need to write that ajax call code is 

Avatar

Employee Advisor

@manikanthar1295 

You can edit the servlet call sample shared previously to include 4 parameters. 

This AJAX call should be invoked as part of the submit action rules of the adaptive form. You can read more about rule editor here[0]

 

[0] - https://experienceleague.adobe.com/docs/experience-manager-65/forms/adaptive-forms-advanced-authorin... 

Avatar

Level 6

Hi,

as per your suggestion i am written code like below is it correct way to write

 

manikanthar1295_0-1649743163235.png

 

 

Avatar

Employee Advisor

@manikanthar1295 Yes, that's how a sling servlet is called. 

You need to make sure that the servlet is registered and that the data parsed from the AF is the expected one for the servlet to process further.

Avatar

Employee Advisor

@manikanthar1295

 Step 1: Test your servlet via postman.

Step 2: If it works via postman then make an AJAX call from the script editor to the servlet.