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 a RESTFUL WCF Service

Avatar

Level 1

I tried this to make a web service call. Is it possible to embed jQuery in the PDF form or what would be the correct way to do this? I am using AEM 6.2

<script contentType="application/x-javascript" name="jsCCTS" src="https://code.jquery.com/jquery-3.1.1.min.js">

       function CallRESTWCF()
        {
            var caseId = $("#txtCaseId").val();
            //I've also tried passing txtCaseId.rawValue   
            varType = "GET";
            varUrl = "http://localhost/WCF_Service/ABCD.svc/" + "GetPersonInfoByCaseIdREST/" + caseId;
            //Data = '{"Id": "' + caseId + '"}';
            varContentType = "application/json; charset=utf-8";
            
            varDataType = "json"; varProcessData = true;
            $.ajax({
                type: varType, //GET or POST or PUT or DELETE verb
                url: varUrl, // Location of the service
                data: varData, //Data sent to server
                contentType: varContentType, // content type sent to server
                dataType: varDataType, //Expected data format from server
                processdata: varProcessData, //True or False
                success: function (msg) {//On Successfull service call
                    //alert(msg);
                    ServiceSucceeded(msg);
                },
                error: function () {
                    alert("service call failed");
                }   
            });
        }

</script>

3 Replies

Avatar

Level 3

Javascript inside a PDF form is a limited version of ECMA JavaScript so script imports are not supported. Another concern you need to be aware of is that while service calls are possible, the form would need to be Reader Extended AND the calls would be Sandboxed to only making calls to the same domain as the form was initially rendered from in the browser.

If you're looking for this level of scripting, move over to Adaptive Forms where client libraries (JS & CSS) is fully supported.

Avatar

Level 1

Thanks for your reply. The forms and the service can be hosted in the same domain. For being Reader Extended, I'm not sure if that would be a licensing or a plugin thing.

I was provided with a PDF form that I would need to prefill with information. Can I convert the PDF form to one that is Adapative ? Sorry every technical term is quite new to me as I have just been into AEM for 2 weeks.

Avatar

Level 2

rpulido20 wrote...

Thanks for your reply. The forms and the service can be hosted in the same domain. For being Reader Extended, I'm not sure if that would be a licensing or a plugin thing.

I was provided with a PDF form that I would need to prefill with information. Can I convert the PDF form to one that is Adapative ? Sorry every technical term is quite new to me as I have just been into AEM for 2 weeks.

 

Making web service call from within the PDF form is usually not a good idea. 

Why are you trying to make web service call from the form? Is your requirement to fetch data based on user action/selection on the form? Or is it just a pre-fill info (meaning that the form must load with this data - for example user's name, address etc)?

For pre-fill info, the best way is to prepare the 'prefill' XML and then call the GeneratePDFForm service to create the final PDF form. Your calling application can do the XML preparation or you could do it as a part of your Orchestration on AEM/Livecycle. 

For user action based data prefill needs, you can use something called "Form Bridge". It basically allows you to communicate between the PDF Form and the parent HTML page.

For example - if you wanted to capture zip code on the form and populate City and State by making a service call so that your user don't have to enter it, you would use Form Bridge to call Javascript function of the parent HTML. JS function of the parent is then responsible for getting the data (by calling whatever service you need) and then send the data back to the PDF form. Since your parent JS does not have limited JS functionality, you could make that Ajax call. 

Regards,

Priyank Pardiwala