Showing posts with label REST API. Show all posts
Showing posts with label REST API. Show all posts

Sunday, April 7, 2024

Page Composer - Enabling Button and executing SOAP/REST API in Oracle fusion

Using Page Composer one can enable a custom Button and execute the SOAP/REST API dynamically by passing the parameters using the Bind parameters available in Oracle Fusion page. 
Follow the steps mentioned below.
 
Enable the Page Composer using Sandbox. (Configuration > Sandboxes > Create Sandbox)

Name : customButton
Publishable: Yes
Select Checkbox for Page Composer 

Navigate to the Page where the button needed. For the blog I'm creating the button On "Transactions" Page where user can click the button and submit an ESS job "Print Receivables Transactions" to print the invoice and attach the pdf to the invoice also send an copy of invoice to the customer. 

Navigate to Receivables > Billing > Manage Transaction

After opening the transaction window Click on Tools > Page Composer

Click On the "Structure" tab and pull the page towards Up from the bottom so that the technical components of the page can be visible.

Under the "Miscellaneous" Tab, just above the Generate Bill will be adding the Button so hover the cursor and select the main frame of the "Generate Bill" Section.

Click the Add "+" button on the Dock. Make sure the Frame element "panelFromLayout" is selected.

Click on "Open" next to "Component" in the Add Content window.

Click on "+ Add" next to the HTML Markup in the available components and click on "Close" button.

After adding the HTML Markup, you should see the "HTML Markup" is added on the page and two new elements added to "panelFormLAyout". 


Select the "<>outputTest: New HTML Markup" and click on gear icon (Show the properties of New HTML Markup).
In the "Component Properties" window click the Down arrow next to the "Value" and select the "Expression Builder".

In the "Expression Builder Copy paste the below code (Kindly modify the code as per your requirement" and test the code before deploying it in the Production or any of your environment. 


<html>
<body>
<button id="custCompleteAndReview" class="button" onclick="(function(p_org_id, p_trx_number){
//console.log('Parameters received are : '+p_org_id+'-'+p_trx_number);
var xmlhttp = new XMLHttpRequest();
var finalurl = 'https://' + window.location.host + '/fscmService/ErpIntegrationService';
xmlhttp.open('POST', finalurl, true);
credentials = 'Basic ' + 'c3ZjLnBOkludGVncmF0aW9zZXJAMTIzNA==';
xmlhttp.setRequestHeader('Authorization', credentials);
var sr = '<soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:typ=&quot;http://xmlns.oracle.com/apps/financials/commonModules/shared/model/erpIntegrationService/types/&quot;> ' +
'<soapenv:Header/> ' +
'<soapenv:Body> ' +
'<typ:submitESSJobRequest> ' +
'<typ:jobPackageName>/oracle/apps/ess/financials/receivables/transactions/shared/</typ:jobPackageName> ' +
'<typ:jobDefinitionName>TransactionPrintProgramEss</typ:jobDefinitionName> ' +
'<typ:paramList>'+ p_org_id + '</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>ANY</typ:paramList> ' +
'<typ:paramList>TRX_NUMBER</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>'+ p_trx_number + '</typ:paramList> ' +
'<typ:paramList>'+ p_trx_number + '</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>N</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>PDF</typ:paramList> ' +
'<typ:paramList>Default Invoice Template</typ:paramList> ' +
'<typ:paramList>Default Credit Memo Template</typ:paramList> ' +
'<typ:paramList>Default Debit Memo Template</typ:paramList> ' +
'<typ:paramList>Default Chargeback Template</typ:paramList> ' +
'<typ:paramList>N</typ:paramList> ' +
'<typ:paramList>#NULL</typ:paramList> ' +
'<typ:paramList>-1</typ:paramList> ' +
'</typ:submitESSJobRequest> ' +
'</soapenv:Body> ' +
'</soapenv:Envelope> ' ;
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
let result = extractResultValue(xmlhttp.responseText);
alert ('Print Receivables Transactions ESS job Submitted successfully. Process ID : ' + result );
}
}
}
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send(sr);
function extractResultValue(text) {
var xmlStartIndex = text.indexOf('<env:Envelope');
var xmlEndIndex = text.lastIndexOf('</env:Envelope>') + '</env:Envelope>'.length;
var xmlContent = text.substring(xmlStartIndex, xmlEndIndex);

var parser = new DOMParser();
var xmlDoc = parser.parseFromString(xmlContent, 'text/xml');

var resultTag = xmlDoc.querySelector('result');
if (resultTag) {
return resultTag.textContent;
} else {
return null;
}
}
String.prototype.obfs = function(key, n = 126) {
if (!(typeof(key) === 'number' && key % 1 === 0)
|| !(typeof(key) === 'number' && key % 1 === 0)) {
return this.toString();
}
var chars = this.toString().split('');
for (var i = 0; i < chars.length; i++) {
var c = chars[i].charCodeAt(0);
if (c <= n) {
chars[i] = String.fromCharCode((chars[i].charCodeAt(0) + key) % n);
}
}
return chars.join('');
};
})('', '');return false" > Reprint</button>
</body>
</html> <!-- typo -->


Click on "Test" and Ok to close the Expression Builder Window. 
Click on Apply and OK button in the Component Properties window to close the Properties window. 


Test your code.