Show / Hide Table of Contents

{ "definition": { "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", "actions": { "Analyze_Document_for_Prebuilt_or_Custom_models_(v3.x_API)": { "type": "ApiConnection", "inputs": { "host": { "connection": { "referenceName": "formrecognizer" } }, "method": "post", "body": "@base64ToBinary(outputs('Compose_Base64'))", "headers": { "Content-Type": "application/octet-stream" }, "path": "/documentModels/@{encodeURIComponent('Sync-AI-PO-Template-Model')}:analyze", "queries": { "api-version": "2023-07-31" } }, "runAfter": { "Compose_Base64": [ "SUCCEEDED" ] } }, "Extracted_Json": { "type": "ParseJson", "inputs": { "content": "@body('Analyze_Document_for_Prebuilt_or_Custom_models_(v3.x_API)')?['analyzeResult']", "schema": { "type": "object", "properties": { "documents": { "type": "array", "items": { "type": "object", "properties": { "fields": { "type": "object", "properties": { "OrderNo": { "type": "object", "properties": { "content": { "type": "string" } } } } }, "fields": { "type": "array", "items": { "type": "object", "properties": { "fieldName": { "type": "string" }, "fieldValue": { "type": "object", "properties": { "content": { "type": "string" } } } }, "required": [ "fieldName", "fieldValue" ] } } }, "required": [ "fields", "fields" ] } } } } }, "runAfter": { "Analyze_Document_for_Prebuilt_or_Custom_models(v3.x_API)": [ "SUCCEEDED" ] } }, "For_Each": { "type": "Foreach", "description": "This loop iterates over the valueArray from Extracted_Json, extracting and composing key order details like OrderNo, PartNo, Description, Quantity, ShippedQuantity, Balance, and Price for each item.", "foreach": "@body('Extracted_Json')?['documents'][0]?['fields'][2]?['fieldValue']?['valueArray']", "actions": { "Compose": { "type": "Compose", "inputs": { "PartNo": "@items('For_Each')?['valueObject']?['PartNo']?['content']", "Description": "@items('For_Each')?['valueObject']?['Description']?['content']", "Quantity": "@items('For_Each')?['valueObject']?['Quantity']?['content']" } }, "Append_to_array_variable": { "type": "AppendToArrayVariable", "inputs": { "name": "OrderDetails", "value": "@outputs('Compose')" }, "runAfter": { "Compose": [ "SUCCEEDED" ] } } }, "runAfter": { "Order_No": [ "SUCCEEDED" ] } }, "HTTP-Get_Token": { "type": "Http", "inputs": { "uri": "https://xxxx/auth/realms/xxxx/protocol/openid-connect/token", "method": "POST", "headers": { "Content-Type": "application/x-www-form-urlencoded" }, "body": "client_id=AI_PO_CLIENT&client_secret=MUdXzoeS2ePZfOClsLuRLUe87f7S6lUn&grant_type=client_credentials&scope=openid microprofile-jwt" }, "runAfter": { "For_Each": [ "SUCCEEDED" ] }, "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } } }, "Get_Token": { "type": "ParseJson", "inputs": { "content": "@body('HTTP-Get_Token')", "schema": { "type": "object", "properties": { "access_token": { "type": "string" }, "expires_in": { "type": "integer" }, "refresh_expires_in": { "type": "integer" }, "refresh_token": { "type": "string" }, "token_type": { "type": "string" }, "id_token": { "type": "string" }, "not-before-policy": { "type": "integer" }, "session_state": { "type": "string" }, "scope": { "type": "string" } } } }, "runAfter": { "HTTP-Get_Token": [ "SUCCEEDED" ] } }, "HTTP-Get_IFS_Order_details": { "type": "Http", "inputs": { "uri": "https://addo01-demo.addovation.cloud/main/ifsapplications/projection/v1/PurchaseOrderLinesHandling.svc/PurchaseOrderLineSet?$filter=((startswith(OrderNo%2C%27@{variables('OrderNo')}%27)))", "method": "GET", "headers": { "Authorization": "Bearer @{body('Get_Token')?['access_token']}", "Content-Type": "multipart/mixed; boundary=batch", "Accept": "application/json, text/plain, /", "Accept-Language": "en-US,en;q=0.5", "x-xsrf-token": "a74e977d-cb43-4034-9cd8-bfad31dc0fa2" } }, "runAfter": { "Get_Token": [ "SUCCEEDED" ] }, "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } } }, "IFS_Json": { "type": "ParseJson", "inputs": { "content": "@body('HTTP-Get_IFS_Order_details')", "schema": { "type": "object", "properties": { "@@odata.context": { "type": "string" }, "value": { "type": "array", "items": { "type": "object", "properties": { "@@odata.etag": { "type": "string" }, "luname": { "type": "string" }, "OrderNo": { "type": "string" }, "LineNo": { "type": "string" }, "ReleaseNo": { "type": "string" }, "VendorNo": { "type": "string" }, "PartNo": { "type": "string" }, "Description": { "type": "string" }, "BuyQtyDue": { "type": "integer" }, "VendorPartNo": {}, "BuyUnitMeas": { "type": "string" }, "RevisedQty": { "type": "integer" }, "PurchaseSite": { "type": "string" }, "BuyerName": { "type": "string" }, "BuyerCode": { "type": "string" }, "DateEntered": { "type": "string" } } } } } } }, "runAfter": { "HTTP-Get_IFS_Order_details": [ "SUCCEEDED" ] } }, "Loop_PDF_Order_Details": { "type": "Foreach", "description": "This loop will iterate through all the PDF item lines using the IFS object. It will compare the PDF order details against the IFS order details. The loop will identify any quantity changes in comparison to IFS and detect any new items included in the PDF.", "foreach": "@variables('OrderDetails')", "actions": { "Loop_IFS_Order_details": { "type": "Foreach", "foreach": "@body('IFS_Json')?['value']", "actions": { "Is_the_Item_and_Quantity_Matched": { "type": "If", "description": "Check if the PDF item line is available in IFS, and also check for any quantity changes.", "expression": { "and": [ { "equals": [ "@replace(items('Loop_PDF_Order_details')?['PartNo'], ' ', '')", "@replace(items('Loop_IFS_Order_details')?['PartNo'], ' ', '')" ] }, { "not": { "equals": [ "@int(items('Loop_PDF_Order_Details')?['Quantity'])", "@items('Loop_IFS_Order_details')?['BuyQtyDue']" ] } } ] }, "actions": { "Set_Is_PDF_item_found_true": { "type": "SetVariable", "inputs": { "name": "IsPDFItemFound", "value": true }, "runAfter": { "Append_quantity_changed_order_items": [ "SUCCEEDED" ] } }, "Append_quantity_changed_order_items": { "type": "AppendToArrayVariable", "inputs": { "name": "ProcessedOrderItems", "value": { "PartNo": "@replace(items('Loop_IFS_Order_details')?['PartNo'], ' ', '')", "Description": "@items('Loop_IFS_Order_details')?['Description']", "NewQty": "@items('Loop_PDF_Order_Details')?['Quantity']", "OldQty": "@items('Loop_IFS_Order_details')?['BuyQtyDue']", "lineno": "@items('Loop_IFS_Order_details')?['LineNo']", "releaseno": "@items('Loop_IFS_Order_details')?['ReleaseNo']", "Status": "qty_changed" } } } }, "else": { "actions": { "Is_item_line_and_qty_matching": { "type": "If", "expression": { "and": [ { "equals": [ "@replace(items('Loop_PDF_Order_details')?['PartNo'], ' ', '')", "@replace(items('Loop_IFS_Order_details')?['PartNo'], ' ', '')" ] }, { "equals": [ "@int(items('Loop_PDF_Order_Details')?['Quantity'])", "@items('Loop_IFS_Order_details')?['BuyQtyDue']" ] } ] }, "actions": { "Append_quantity_changed_order_items-copy": { "type": "AppendToArrayVariable", "inputs": { "name": "ProcessedOrderItems", "value": { "PartNo": "@replace(items('Loop_IFS_Order_details')?['PartNo'], ' ', '')", "Description": "@items('Loop_IFS_Order_details')?['Description']", "NewQty": "@items('Loop_PDF_Order_Details')?['Quantity']", "OldQty": "@items('Loop_IFS_Order_details')?['BuyQtyDue']", "lineno": "@items('Loop_IFS_Order_details')?['LineNo']", "releaseno": "@items('Loop_IFS_Order_details')?['ReleaseNo']", "Status": "unchanged" } } }, "Set_Is_PDF_item_found_true-copy": { "type": "SetVariable", "inputs": { "name": "IsPDFItemFound", "value": true }, "runAfter": { "Append_quantity_changed_order_items-copy": [ "SUCCEEDED" ] } } }, "else": { "actions": {} } } } } } }, "runAfter": { "Set_default_Is_PDF_item_found": [ "SUCCEEDED" ] }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } } }, "Set_default_Is_PDF_item_found": { "type": "SetVariable", "inputs": { "name": "IsPDFItemFound", "value": false } }, "Is_PDF_item_new": { "type": "If", "expression": { "and": [ { "equals": [ "@variables('IsPDFItemFound')", false ] } ] }, "actions": { "HTTP_-Get_Part_And_Part_Supplier_Info(Validate)": { "type": "Http", "inputs": { "uri": "https://addo01-demo.addovation.cloud/main/ifsapplications/projection/v1/PurchaseOrderHandling.svc/GetPartAndPartSupplierInfo(OrderNo='@{variables('OrderNo')}',PartNo='@{replace(items('Loop_PDF_Order_Details')?['PartNo'], ' ', '')}',PurchaseSite='@{variables('Contract')}',VendorNo='@{body('Item_line_default_json')?['InvoicingSupplier']}',Contract='@{variables('Contract')}')", "method": "GET", "headers": { "Authorization": "Bearer @{body('Get_Token')?['access_token']}" } }, "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } } }, "Do_Part_No_and_Supplier_exist": { "type": "If", "expression": { "and": [ { "equals": [ "@variables('IsPartExistsDb')", "True" ] } ] }, "actions": { "Set_IsOrderConfirmationAllowed": { "type": "SetVariable", "inputs": { "name": "IsOrderConfirmationAllowed", "value": true }, "runAfter": { "HTTP_-Get_Fbuy_Unit_Price": [ "SUCCEEDED" ] } }, "HTTP-Get_Fbuy_Unit_Price": { "type": "Http", "inputs": { "uri": "https://addo01-demo.addovation.cloud/main/ifsapplications/projection/v1/PurchaseOrderHandling.svc/Reference_InventoryPart?$filter=Contract eq '@{variables('Contract')}' and PartNo eq '@{replace(items('Loop_PDF_Order_Details')?['PartNo'], ' ', '')}'", "method": "GET", "headers": { "Authorization": "Bearer @{body('Get_Token')?['access_token']}" } }, "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } } }, "Append_new_order_items": { "type": "AppendToArrayVariable", "inputs": { "name": "ProcessedOrderItems", "value": { "Qty": "@int(items('Loop_PDF_Order_Details')?['Quantity'])", "OrderNo": "@variables('OrderNo')", "BuyQtyDue": "@int(items('Loop_PDF_Order_Details')?['Quantity'])", "CurrencyRate": 1, "Description": "@items('Loop_PDF_Order_Details')?['Description']", "FbuyUnitPrice": "@body('HTTP-Get_Fbuy_Unit_Price')?['value'][0]['EstimatedMaterialCost']", "Contract": "@variables('Contract')", "AddressId": "@variables('AddressId')", "PartNo": "@replace(items('Loop_PDF_Order_Details')?['PartNo'], ' ', '')", "Status": "new" } }, "runAfter": { "Set_IsOrderConfirmationAllowed": [ "SUCCEEDED" ] } } }, "else": { "actions": {} }, "runAfter": { "Set_PartExistsDb": [ "SUCCEEDED" ] } }, "Set_PartExistsDb": { "type": "SetVariable", "inputs": { "name": "IsPartExistsDb", "value": "@string(body('HTTP-Get_Part_And_Part_Supplier_Info(Validate)')?['PartExistsDb'])" }, "runAfter": { "HTTP_-Get_Part_And_Part_Supplier_Info(Validate)": [ "SUCCEEDED" ] } } }, "else": { "actions": {} }, "runAfter": { "Loop_IFS_Order_details": [ "SUCCEEDED" ] } } }, "runAfter": { "Processed_Order_Items": [ "SUCCEEDED" ] }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } } }, "Loop_IFS_order_details_II": { "type": "Foreach", "description": "This loop will iterate through the IFS item lines against the PDF item lines. It will identify whether any item lines present in the IFS are deleted in the PDF", "foreach": "@body('IFS_Json')?['value']", "actions": { "Loop_PDF_Order_Details_II": { "type": "Foreach", "foreach": "@variables('OrderDetails')", "actions": { "Will_Continue_Loop_and_item_to_item_match": { "type": "If", "expression": { "and": [ { "equals": [ "@variables('IsIFSItemLineFound')", false ] }, { "equals": [ "@replace(trim(items('Loop_IFS_Order_Details_II')?['Description']), ' ', ' ')", "@replace(trim(items('Loop_PDF_Order_Details_II')?['Description']), ' ', ' ')" ] } ] }, "actions": { "Set_Item_Found_True": { "type": "SetVariable", "inputs": { "name": "IsIFSItemLineFound", "value": true } } }, "else": { "actions": {} } } }, "runAfter": { "Set_Default_Item_Found": [ "SUCCEEDED" ] }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } } }, "Set_Default_Item_Found": { "type": "SetVariable", "inputs": { "name": "IsIFSItemLineFound", "value": false } }, "Should_Item_Delete": { "type": "If", "expression": { "or": [ { "equals": [ "@variables('IsIFSItemLineFound')", false ] } ] }, "actions": { "Append_deleted_order_items": { "type": "AppendToArrayVariable", "inputs": { "name": "ProcessedOrderItems", "value": { "PartNo": "@items('Loop_IFS_Order_Details_II')?['PartNo']", "Description": "@items('Loop_IFS_Order_Details_II')?['Description']", "lineno": "@items('Loop_IFS_Order_Details_II')?['LineNo']", "releaseno": "@items('Loop_IFS_Order_Details_II')?['ReleaseNo']", "BuyQtyDue": "@items('Loop_IFS_Order_Details_II')?['BuyQtyDue']", "Status": "deleted", "Etag": "@replace(items('Loop_IFS_Order_Details_II')?['@odata.etag'], '\', '')" } } } }, "else": { "actions": {} }, "runAfter": { "Loop_PDF_Order_Details_II": [ "SUCCEEDED" ] } } }, "runAfter": { "Is_IFS_Item_Line_Found": [ "SUCCEEDED" ] }, "runtimeConfiguration": { "concurrency": { "repetitions": 1 } } }, "HTTP_-Get_item_line_default_details": { "type": "Http", "inputs": { "uri": "https://xxxx/main/ifsapplications/projection/v1/PurchaseOrderHandling.svc/PurchaseOrderSet(OrderNo='@{variables('OrderNo')}')/LinePartArray/IfsApp.PurchaseOrderHandling.PurchaseOrderLinePart_Default()\n", "method": "GET", "headers": { "Authorization": "Bearer @{body('Get_Token')?['access_token']}" } }, "runAfter": { "Is_PDF_item_found": [ "SUCCEEDED" ] }, "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } } }, "Item_line_default_json": { "type": "ParseJson", "inputs": { "content": "@body('HTTP-Get_item_line_default_details')", "schema": { "type": "object", "properties": { "AddressId": { "type": "string" }, "InvoicingSupplier": { "type": "string" }, "PurchaseSite": { "type": "string" } } } }, "runAfter": { "HTTP-Get_item_line_default_details": [ "SUCCEEDED" ] } }, "Filter_array": { "type": "Query", "inputs": { "from": "@triggerBody()?['attachments']", "where": "@equals(item()?['contentType'], 'application/pdf')" }, "runAfter": {} }, "Get_Attachment(V2)": { "type": "ApiConnection", "inputs": { "host": { "connection": { "referenceName": "office365-3" } }, "method": "get", "path": "/codeless/v1.0/me/messages/@{encodeURIComponent(triggerBody()?['id'])}/attachments/@{encodeURIComponent(first(body('Filter_array'))?['id'])}", "queries": { "extractSensitivityLabel": false, "fetchSensitivityLabelMetadata": false } }, "runAfter": { "Filter_array": [ "SUCCEEDED" ] } }, "Compose_Base64": { "type": "Compose", "inputs": "@body('Get_Attachment_(V2)')?['contentBytes']", "runAfter": { "Get_Attachment_(V2)": [ "SUCCEEDED" ] } }, "Update_Order_Details": { "type": "SetVariable", "inputs": { "name": "ProcessedOrderDetails", "value": { "id": "@{guid()}", "orderNo": "@{variables('OrderNo')}", "supplier": "@{body('IFS_Json')?['value'][0]?['BuyerName']}", "site": "@{body('IFS_Json')?['value'][0]?['PurchaseSite']}", "orderDate": "@{formatDateTime(body('IFS_Json')?['value'][0]?['DateEntered'], 'yyyy-MM-dd')\r\n}", "changeRequestedOn": "@{formatDateTime(utcNow(), 'yyyy-MM-dd')}", "requestedBy": "@triggerBody()?['from']", "items": "@variables('ProcessedOrderItems')", "approvedBy": "@first(body('HTTP_-Fetch_email_recipient')?['value'])?['Value']", "approvedOn": "", "approvedStatus": "Pending", "comment": "", "attachmentName": "@first(body('Filter_array'))?['name']" } }, "runAfter": { "HTTP-Fetch_email_recipient": [ "SUCCEEDED" ] } }, "Create_or_update_item": { "type": "ServiceProvider", "inputs": { "parameters": { "databaseId": "AI-POC-DB", "containerId": "po-confirmation-detail", "item": "@variables('ProcessedOrderDetails')", "isUpsert": true }, "serviceProviderConfiguration": { "connectionName": "AzureCosmosDB", "operationId": "CreateOrUpdateDocument", "serviceProviderId": "/serviceProviders/AzureCosmosDB" } }, "runAfter": { "Update_Order_Details": [ "SUCCEEDED" ] } }, "Send_an_email(V2)": { "type": "ApiConnection", "inputs": { "host": { "connection": { "referenceName": "office365-1" } }, "method": "post", "body": { "To": "@first(body('HTTP_-Fetch_email_recipient')?['value'])?['Value']", "Subject": "Action Needed: Order @{variables('OrderNo')} Review", "Body": "<p class="editor-paragraph">Dear @{first(body('HTTP-Fetch_email_recipient')?['value'])?['name']},
This is an automated system notification from <strong class="editor-text-bold">Addovation.
Order @{variables('OrderNo')} has been updated and requires your review before proceeding.
You can review the details here:
<a href="http://syncaipo-service.azurewebsites.net/order/@{variables('OrderNo')}/@{variables('CustomerId')}" class="editor-link">View Order Changes
If you have any questions, please reach out to the operations team.

<p class="editor-paragraph">
Thank you,
Addovation System Notification", "Importance": "Normal", "IsHtml": "true" }, "path": "/v2/Mail" }, "runAfter": { "Save_PDF_to_Blob": [ "SUCCEEDED" ] } }, "Is_IFS_Item_Line_Found": { "type": "InitializeVariable", "inputs": { "variables": [ { "name": "IsIFSItemLineFound", "type": "boolean", "value": false } ] }, "runAfter": { "Loop_PDF_Order_Details": [ "SUCCEEDED" ] } }, "Is_PDF_item_found": { "type": "InitializeVariable", "inputs": { "variables": [ { "name": "BuyerCode", "type": "string", "value": "@{body('IFS_Json')?['value']?[0]?['BuyerCode']}" }, { "name": "ETag", "type": "string" }, { "name": "IsPDFItemFound", "type": "boolean", "value": false } ] }, "runAfter": { "IFS_Json": [ "SUCCEEDED" ] } }, "Order_No": { "type": "InitializeVariable", "inputs": { "variables": [ { "name": "OrderDetails", "type": "array", "value": [] }, { "name": "OrderNo", "type": "string", "value": "@{first(body('Extracted_Json')?['documents'])?['fields']?['OrderNo']?['content']}" }, { "name": "CustomerId", "type": "string", "value": "00020E90170F813EA438B3EBC97B0FF8FC8694A29FF07456CD465F121FE2F401B2227" } ] }, "runAfter": { "Extracted_Json": [ "SUCCEEDED" ] } }, "Processed_Order_Items": { "type": "InitializeVariable", "inputs": { "variables": [ { "name": "Contract", "type": "string", "value": "@body('Item_line_default_json')?['PurchaseSite']" }, { "name": "AddressId", "type": "string", "value": "@body('Item_line_default_json')?['AddressId']" }, { "name": "IsOrderConfirmationAllowed", "type": "boolean", "value": false }, { "name": "IsPartExistsDb", "type": "string", "value": "false" }, { "name": "ProcessedOrderDetails", "type": "object", "value": { "orderNo": "", "items": [] } }, { "name": "ProcessedOrderItems", "type": "array", "value": [] } ] }, "runAfter": { "Item_line_default_json": [ "SUCCEEDED" ] } }, "HTTP-Fetch_email_recipient": { "type": "Http", "inputs": { "uri": "@concat(\r\n 'https://xxxx/main/ifsapplications/projection/v1/PersonHandling.svc/PersonInfoSet(PersonId=''', \r\n variables('BuyerCode'), \r\n ''')/CommunicationMethods?$filter=MethodId%20eq%20IfsApp.PersonHandling.CommMethodCode''EMail'''\r\n)\r\n", "method": "GET", "headers": { "Authorization": "Bearer @{body('Get_Token')?['access_token']}" } }, "runAfter": { "Loop_IFS_order_details_II": [ "SUCCEEDED" ] }, "runtimeConfiguration": { "contentTransfer": { "transferMode": "Chunked" } } }, "Save_PDF_to_Blob": { "type": "ApiConnection", "inputs": { "host": { "connection": { "referenceName": "azureblob" } }, "method": "post", "body": "@base64ToBinary(first(triggerOutputs()?['body/attachments'])?['contentBytes'])", "headers": { "x-ms-blob-content-type": "application/pdf" }, "path": "/v2/datasets/@{encodeURIComponent(encodeURIComponent('AccountNameFromSettings'))}/files", "queries": { "folderPath": "/po-confirmation-pdf-container", "name": "@{first(body('Filter_array'))?['name']}", "queryParametersSingleEncoded": true } }, "runAfter": { "Create_or_update_item": [ "SUCCEEDED" ] } } }, "contentVersion": "1.0.0.0", "outputs": {}, "triggers": { "When_a_new_email_arrives(V3)": { "type": "ApiConnectionNotification", "inputs": { "host": { "connection": { "referenceName": "office365-3" } }, "fetch": { "pathTemplate": { "template": "/v3/Mail/OnNewEmail" }, "method": "get", "queries": { "importance": "Any", "fetchOnlyWithAttachment": true, "includeAttachments": true, "subjectFilter": "Order Confirmation", "folderPath": "Inbox" } }, "subscribe": { "body": { "NotificationUrl": "@listCallbackUrl()" }, "pathTemplate": { "template": "/GraphMailSubscriptionPoke/$subscriptions" }, "method": "post", "queries": { "importance": "Any", "fetchOnlyWithAttachment": true, "folderPath": "Inbox" } } }, "splitOn": "@triggerBody()?['value']" } } }, "kind": "Stateful" }
  • Edit this page
In this article
Back to top Generated by DocFX