E9.2 Consuming Inbound REST Message

badariv

Member
We are on JDE

Application Release : E9.2

Tools Release: 9.2.6.3

We are in the process of developing Vendor Invoice approval process in JDE.

Our management decided to utilize Microsoft Power Automate for sending vendor Invoice information along with Vendor Invoice (PDF) using MS Power Automate to the Approver for approval.

1) User creates Vendor Invoice information along with vendor invoice pdf as attachment in JDE.
2) Vendor initiates the approval process by updating Approver Email into a custom table.
3) This information along with Approver info and pdf needs to be sent to MS Power automate, so that the Workflow designed in Power Automate will send an email / Teams message to approver.

The issues I need help from the group is as below
1) I am sending Vendor Invoice and approver email info using REST - PUT message connector to Microsoft Power Automate. (REST-PUT --> JDE to MS Power Automate)
2) I am not able to figure out how to send Vendor Invoice PDF along with PUT message. *** Need help
3) After the approver approves/Rejects along with comment text, MS Power Automate sends back that information to JDE (REST-PUT --> MS Power Automate to JDE)
4) I am not able to figure out how to receive .json message from MS Power Automate and process the next steps based on Approval Status.
I am enclosing .json file which will be using for communication between JDE & MS Power Automate.

Regards
Badri Vadlamani
Sr Financial Systems Engineer
MicroStrategy Inc
 

Attachments

  • JSON_ApprovalRequest_OUT.txt
    1.3 KB · Views: 6
Hi Badri, thanks for the excellent write-up!

I think that the issues and hurdles you face call for more, scope-wise, than what I limit myself to on this forum, which is "~5 minute support" (more if the issue is a problem I'm dealing with myself)

The issue of pulling a PDF from JDE and sending it across to an API will require lots of back & forth and specific knowledge. I think this is something you should hire consulting time to resolve.

Receiving REST info back from the power automate step (why is it a PUT? Is power automate returning a binary file?) can be tricky if in your case it involves a PUT/file handling/parsing/storage. In general, the 2nd half of your integration would involve you spinning up an orchestration endpoint with inputs to match the outputs from PowerAutomate. At that point it's a matter of finding the endpoint (/jderest/v3/orchestrator/ORCHNAME) and making sure the networking/auth is set up so that they can talk.

Lots to digest! I think it's a bit too much for a "quick help" spot like JDEList. Good luck!
 
My experience uploading to Microsoft is that you may need to write a custom script to upload a file, rather than use a REST connector. The implementation of the File Upload in the REST connector did not align with the API requirements on the Microsoft side so I had to do it myself. That is what I have done with SharePoint in the past.
 
Thanks Dave and Kevin for the info.

Dave : As you said, we decided to create an Orchestrator "MSAUTOMATEIN" which will be invoked directly by Power Automate using the end point "http:/<AISSERVER>:port//jderest/v3/orchestrator/MSAUTOMATEIN" taking output from Power Automate as input to Orchestrator.

I just created an Orchestrator "MSAUTOMATEOUT" with connector having Power Automate End Point and added .json logic in the body. I tested this orchestrator and it worked and initiated the Workflow in Power Automate.

I am still figuring out solution to attach vendor invoice pdf to the "MSAUTOMATEOUT".
I have a thought process of downloading pdf as using "Media Object Download Request - Output to File" and save it a share point location and provide link during execution of "MSAUTOMATEOUT"
 
My experience uploading to Microsoft is that you may need to write a custom script to upload a file, rather than use a REST connector. The implementation of the File Upload in the REST connector did not align with the API requirements on the Microsoft side so I had to do it myself. That is what I have done with SharePoint in the past.
In a old project (release 21) we have to do a groovy script to upload pdf to sharepoint trought microsoft graph, because PUT method doesn't allow attach file. But in currently in release 23 I achieve to do with a connector to upload to sharepoint :) If you need I could share.
 
Thanks Dave and Kevin for the info.

Dave : As you said, we decided to create an Orchestrator "MSAUTOMATEIN" which will be invoked directly by Power Automate using the end point "http:/<AISSERVER>:port//jderest/v3/orchestrator/MSAUTOMATEIN" taking output from Power Automate as input to Orchestrator.

I just created an Orchestrator "MSAUTOMATEOUT" with connector having Power Automate End Point and added .json logic in the body. I tested this orchestrator and it worked and initiated the Workflow in Power Automate.

I am still figuring out solution to attach vendor invoice pdf to the "MSAUTOMATEOUT".
I have a thought process of downloading pdf as using "Media Object Download Request - Output to File" and save it a share point location and provide link during execution of "MSAUTOMATEOUT"
badariv, and why not consume from MS Power the standard service REST for attachment later you call MSAUTOMATEOUT?? https://docs.oracle.com/en/applicat...duct/9.2/rest-api/op-v2-file-upload-post.html
 
In a old project (release 21) we have to do a groovy script to upload pdf to sharepoint trought microsoft graph, because PUT method doesn't allow attach file. But in currently in release 23 I achieve to do with a connector to upload to sharepoint :) If you need I could share.
Hi Alfred
Can you share process you used to upload to share-point?
I need to send vendor invoice information and pdf in one request. Since during POST service request, it's not possible to attach PDF, i am planning to upload PDF to share- point and send the share point link to POST service request
 
Based on the return POST message MS Automate, I was running an UBE from Orchestrator to complete the next steps after approval. I was not able to assign Orchestrator input values from MS Power Automate to UBE Report Interconnect ?Any Help ?
 
Based on the return POST message MS Automate, I was running an UBE from Orchestrator to complete the next steps after approval. I was not able to assign Orchestrator input values from MS Power Automate to UBE Report Interconnect ?Any Help ?
I share groovy script:

Java:
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
import groovy.json.*;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
    HashMap<String, Object> returnMap = new HashMap<String, Object>();
    String API_Server = (String)inputMap.get("API_Server");
    String Token = (String)inputMap.get("token");
    String FilePath = (String)inputMap.get("FilePath");
    String nombre = (String)inputMap.get("Nombre");

    URLConnection urlconnection = null;

    try {
        
        urlconnection = new URL(API_Server + nombre + ":/content").openConnection();
        urlconnection.setDoOutput(true);
        urlconnection.setDoInput(true);
        urlconnection.setRequestMethod("PUT");
        urlconnection.setRequestProperty("Authorization", "Bearer " + Token);
        urlconnection.setRequestProperty("Content-type", "application/pdf");
        urlconnection.connect();
        
        BufferedOutputStream bos = new BufferedOutputStream(urlconnection.getOutputStream());
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(FilePath)));
        
       // read byte by byte until end of stream
        while ((i = bis.read()) > -1) {
            bos.write(i);
        }
        bis.close();
        bos.close();
        int j;
    
        int responseCode = urlconnection.getResponseCode();
        returnMap.put("Code",responseCode);
        if ((responseCode >= 200) && (responseCode <= 202)) {
            slurper = new JsonSlurper().parseText(urlconnection.inputStream.text);
            returnMap.put("Resultado",slurper);

        }
        else {
            slurper = new JsonSlurper().parseText(urlconnection.errorStream.text);
            returnMap.put("Resultado",slurper);
        }
        urlconnection.disconnect();
        } catch (Exception e) {           
            returnMap.put("Resultado",e);
        }

  return returnMap;
}
 
I share groovy script:

Java:
import com.oracle.e1.common.OrchestrationAttributes;
import java.text.SimpleDateFormat;
import groovy.json.*;
HashMap<String, Object> main(OrchestrationAttributes orchAttr, HashMap inputMap)
{
    HashMap<String, Object> returnMap = new HashMap<String, Object>();
    String API_Server = (String)inputMap.get("API_Server");
    String Token = (String)inputMap.get("token");
    String FilePath = (String)inputMap.get("FilePath");
    String nombre = (String)inputMap.get("Nombre");

    URLConnection urlconnection = null;

    try {
       
        urlconnection = new URL(API_Server + nombre + ":/content").openConnection();
        urlconnection.setDoOutput(true);
        urlconnection.setDoInput(true);
        urlconnection.setRequestMethod("PUT");
        urlconnection.setRequestProperty("Authorization", "Bearer " + Token);
        urlconnection.setRequestProperty("Content-type", "application/pdf");
        urlconnection.connect();
       
        BufferedOutputStream bos = new BufferedOutputStream(urlconnection.getOutputStream());
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(FilePath)));
       
       // read byte by byte until end of stream
        while ((i = bis.read()) > -1) {
            bos.write(i);
        }
        bis.close();
        bos.close();
        int j;
   
        int responseCode = urlconnection.getResponseCode();
        returnMap.put("Code",responseCode);
        if ((responseCode >= 200) && (responseCode <= 202)) {
            slurper = new JsonSlurper().parseText(urlconnection.inputStream.text);
            returnMap.put("Resultado",slurper);

        }
        else {
            slurper = new JsonSlurper().parseText(urlconnection.errorStream.text);
            returnMap.put("Resultado",slurper);
        }
        urlconnection.disconnect();
        } catch (Exception e) {          
            returnMap.put("Resultado",e);
        }

  return returnMap;
}
Hi Alfred
Thanks for detailed code. I am entirely new to this Orchestration world. If possible, can you give me steps/document how to add this code orchestrator
1709312782716.png
1709312865427.png
1709312984899.png
 
Hi Alfred
Thanks for detailed code. I am entirely new to this Orchestration world. If possible, can you give me steps/document how to add this code orchestrator
View attachment 20093
View attachment 20094
View attachment 20095
previously you need get a token, there here a example with postman (you can find a lot of information, for example: https://dzone.com/articles/getting-access-token-for-microsoft-graph-using-oau ):
1709326426320.png
you can implemented this with a conection and connector, and pass the token to groovy to upload file.
if you want or need update later metadata, you should call to other method.

Microsoft graph there are a lot of information by internet, it's powerful but not it's easy or intuitive (at least for me XD)

Regards.
 
Thanks Alfredorz
I am facing issue with Custom JRuby code to parse JSON Array from MS Power Automate and assign it to variables, so that I can assign those variables to Report Interconnect for completing the next steps.
JASON Array:
{
"ProformaInvoice": [
{
"UniqueID": 0,
"CompanyKey": "string",
"DocumentType": "string",
"DocumentNumber": 0,
"AddressNumber": 0,
"AmountGross": 0,
"VendorInvoiceNumber": "string"
}
],
"ApprovalStatusInfo": [
{
"ApprovalActionCode": "string",
"ApprovalMessage": "string"
}
]
}
*********************
JRuby Code:

require 'json'

def main(orchAttr, inputMap)

returnMap = {}

# Parse JSON
data = JSON.parse(inputMap)

# Accessing values and mapping to JDE Orchestrator variables

proforma_invoice = data['ProformaInvoice'][0]
approval_statusinfo = data['ApprovalStatusInfo'][0]

# Add logic here
stringVal = inputMap["inputStringVal"]
numVal = inputMap["inputNumVal"].to_f
#

orchAttr.writeWarn("Ruby Warn ")
orchAttr.writeDebug("Ruby Debug ")

hash1 = {
"company_key" => proforma_invoice['CompanyKey'],
"document_type" => proforma_invoice['DocumentType'],
"vendor_invoicenumber" => proforma_invoice['VendorInvoiceNumber'].strip,
"approval_actioncode" => approval_statusinfo['ApprovalActionCode'],
"approval_message" => approval_statusinfo['ApprovalMessage']
}
array = []
array << hash1

hash2 = {
"unique_id" => proforma_invoice['UniqueID'],
"document_number" => proforma_invoice['DocumentNumber'],
"address_number" => proforma_invoice['AddressNumber'],
"amount_gross" => proforma_invoice['AmountGross']
}
array << hash2
returnMap["Output Array"] = JSON.generate(array)

returnMap["Output String"] = stringVal
returnMap["Output Attrib"] = "AB" + orchAttr.getAddressNumber().to_s

return returnMap
end
_____________

Got the below Error message:
{
"message": {
"MAPJSON": {
"Exception": "Exception",
"Message": "org.jruby.embed.InvokeFailedException: (TypeError) no implicit conversion of Java::JavaUtil::HashMap into String: at RUBY.main(<script>:8)"
}
},
"exception": "Exception",
"timeStamp": "2024-03-09T17:22:08.284-0500",
"userDefinedErrorText": "",
"status": "ERROR"
}
 
Last edited:
Hi badariv,
inputMap is the global input array of function, you need define a input variable inside inputMap as your json and work with this. For example:

1710146029299.png

And from here, work with the data as you need.

Regards.
 
Ah, do you need pass a value in inputMSJson, of course. Or check previously if is blank or null, else JSON.parse shot a exception.
 
Back
Top