web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Business Central Custom Teams Adaptive Card︎

JAngle Profile Picture JAngle 133

BC is awash with Microsoft Teams touch points. My contribution to the sub topic is to furnish users with a card of financial data. This is a central way to distribute the information and provides an option outside of a regular report view. Here is an example of the end result:

Thankfully the standard BC API comes with an endpoint which is highly suitable – agedaccountsreceivable_get. There are a few others in the BC standard API list which fit the bill too: cashFlowStatement, agedAccountsPayable, trialBalance etc.

The handy thing about the agedAccountsReceivable endpoint is that it comes with a “Total” section  check out the example payload:

"value": [
        {
            "@odata.etag": "W/\"JzE5OzkxNDA2OTk1MDYwNDE0ODYxNzMxOzAwOyc=\"",
            "customerId": "00000000-0000-0000-0000-000000000000",
            "customerNumber": "",
            "name": "Total",
            "currencyCode": "",
            "balanceDue": 44005.48,
            "currentAmount": 0,
            "period1Amount": 1236.6,
            "period2Amount": 15109.44,
            "period3Amount": 27659.44,
            "agedAsOfDate": "2023-05-24",
            "periodLengthFilter": "30D"
        }
    ]

Things look decent. However, a minor drawback of the standard API is that it breaks the data up differently to the standard BC report you get in the UI

The report has 5 buckets in total, whereas the API uses 4 buckets (ageing bands). The totals are the exact same it is just how the values are split. The API uses period3Amount as anything 61 days and older. The report has the ability to display the data in a few other ways. Not a big draw back but something to consider. I will explain how to get around this after we have the standard version firing data into Teams

Microsoft kindly provide a few adaptive card templates. It was in fact this template which caught my eye and gave me the idea for this post: https://github.com/pnp/AdaptiveCards-Templates/tree/main/samples/payslip. If you’re new to the concept merely pick up a template and open up https://adaptivecards.io/designer/ and paste in the example json. I have a specific one for you to use if you want to achieve the same result as me. It is handy to use the designer to verify your final JSON object validates. There is of course a need for various pieces of text to be swapped out for dynamic values from BC data.

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.4",
    "__comment": "Elements used",
    "body": [
        {
            "type": "Container"
        },
        {
            "type": "TextBlock",
            "text": "Aged Debtors Report",
            "wrap": true,
            "horizontalAlignment": "Center",
            "size": "ExtraLarge",
            "fontType": "Default",
            "weight": "Bolder"
        },
        {
            "type": "TextBlock",
            "text": "As of ",
            "wrap": true,
            "horizontalAlignment": "Center",
            "size": "Medium",
            "fontType": "Default"
        },
        {
            "type": "Container",
            "items": [
                {
                    "type": "Image",
                    "url": "https://raw.githubusercontent.com/pnp/AdaptiveCards-Templates/main/samples/payslip/assets/img_spacer.png"
                },
                {
                    "type": "TextBlock",
                    "text": "By Ageing Band",
                    "wrap": true,
                    "weight": "Bolder",
                    "color": "Accent",
                    "size": "Large"
                }
            ],
            "spacing": "ExtraLarge"
        },
        {
            "type": "Container",
            "items": [
                {
                    "type": "TextBlock",
                    "wrap": true,
                    "weight": "Bolder"
                },
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "Column",
                            "width": "stretch",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "\n\n0 Days\n\n30 Days\n\n60 Days\n\n61+ Days",
                                    "wrap": true,
                                    "spacing": "Small",
                                    "weight": "Bolder"
                                },
                                {
                                    "type": "Container"
                                }
                            ]
                        },
                        {
                            "type": "Column",
                            "width": "stretch",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "text": "\n\n£\n\n£\n\n£\n\n£",
                                    "wrap": true,
                                    "spacing": "Small",
                                    "horizontalAlignment": "Right",
                                    "weight": "Bolder"
                                }
                            ]
                        }
                    ]
                }
            ],
            "spacing": "Medium"
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "\n\nTOTAL OUTSTANDING",
                            "wrap": true,
                            "weight": "Bolder",
                            "size": "Large",
                            "color": "Accent",
                            "spacing": "ExtraLarge"
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "\n\n£",
                            "wrap": true,
                            "weight": "Bolder",
                            "size": "Medium",
                            "color": "Accent",
                            "horizontalAlignment": "Right",
                            "spacing": "ExtraLarge"
                        }
                    ]
                }
            ]
        },
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "ActionSet",
                            "actions": [
                                {
                                    "type": "Action.OpenUrl",
                                    "title": "👆 Open in System",
                                    "url": "https://businesscentral.dynamics.com/<tenantID>/Sandbox?report=120"
                                }
                            ]
                        }
                    ]
                }
            ],
            "spacing": "ExtraLarge",
            "separator": true
        }
    ],
    "backgroundImage": {
        "horizontalAlignment": "Center"
    }
}

The above has various sections missing so that you can copy/paste without any validation issues. If you set everything as I have it then grab the JSON template from my github. The below images show what I have added in and the formulas used. Only part which is not covered by an image is the OpenUrl action which requires a tenantID and the database name you want to access. These could be variables in the overall flow if you find that easier:

Want to have 1 extra ageing band bucket? Sadly the codeunit which runs this functionality doesn’t have the necessary aspects for us to alter it by events. Instead I elected to extend the table and copy the API page and codeunit. You can find the code on my github https://github.com/JAng13sea/Blogs/BCTeamsARCard

Final version looks like this  just like the BC report but Teamsified! Yep, that’s a word now

This was originally posted here.

Comments

*This post is locked for comments