Saturday, 21 May 2022

Cancel AP Invoices using OIC

 Account Payable (AP) invoices enable you to manage supplier invoices that include header, lines, distributions, installments, and attachments.


Whenever you cancel an invoice all invoice amounts are set to zero and this canceled invoice cant be edited or submitted for processing.


You must ensure the status of the invoice before canceling. Its validation status should not be at least "Validated" or "Canceled" Otherwise it will throw the error.


Oracle ERP provides several rest APIs to handle AP invoices. For more details go through the oracle docs ERP Rest API

Let's understand it using the use case below

Use case: Cancel the AP invoice into ERP, from a web application like VBCS. 

A custom VBCS page displays the details of the invoice and enables features for canceling the invoices. 

To cancel an invoice, three parameters Invoice Number, Business Unit, and Supplier are required.

VBCS calls the OIC service and passes all these three parameters and posts that OIC validates the status and then calls the Oracle ERP rest service to cancel the invoice and sends the response back to VBCS.

Steps on OIC side

1. Expose rest service with three parameters to VBCS 

2. Once OIC will receive the request it will call ERP AP to get invoice details service

3. OIC will check the approval status which should not be either approved or canceled and Paid status should be unpaid

4. If the above condition becomes true, OIC will call the Oracle ERP AP to cancel the invoice for the rest API

5. OIC will return the response to VBCS

API Details to getting invoice details are 

API Details to get an invoice details

curl --location --request GET 'https://XXXXX-fusion-instance/fscmRestApi/resources/11.13.18.05/invoices?
q=InvoiceNumber=XXXXXXXX
&onlyData=true
&fields=InvoiceId,InvoiceNumber,BusinessUnit,Supplier,ValidationStatus,PaidStatus' \
--header 'Authorization: Basic fusoin-username:fusion-passwrod='
where q will work as a where clause
onlydata had Boolean values either true or false where true means only data will come not the links
fields will enable you to fetch only selected columns from ERP



Once you will have response from ERP apply the condition
PaidStatus = "Unpaid" and ValidationStatus != "Validated" or ValidationStatus != "Canceled"



Request mapping for Cancel API: There is a trick. As invoice number, business unit, and supplier are object types and these are being passed as an object of the array as request payload for cancel invoice operation. so you have to create an array of objects by creating three duplicate tags for parameters and need to map as per the below mapping.

API Details to cancel the invoice

curl --location --request POST 'https://XXXXX-fusion-instance/fscmRestApi/resources/11.13.18.05/invoices' \

--header 'Authorization: Basic fusoin-username:fusion-passwrod=' \

--header 'Content-Type: application/vnd.oracle.adf.action+json' \

--data-raw '{

"name": "cancelInvoice",

"parameters": [{

"InvoiceNumber": "XXXXXX"

},

{

"BusinessUnit": "XXXXX_BU"

},

{

"Supplier": "XXXXX_Suplier"

}

]

}'



Response from ERP rest AP cancel API for success scenario


How to handle the error let's say you have not applied the switch condition to check whether an invoice is canceled or not and directly you tried it then it will throw the error and the error will be caught on the fault object named instance filed

To handle the error drag and drop the scope activity and then reposition the cancel rest API adapter into the scope and configure the fault and throw the error message by getting the substring from the instance.


References

No comments:

Post a Comment