cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nk1ng
Helper II
Helper II

Bot Framework // Excluding part of JSON?

Happy Friday All!

 

So I made an adaptive carousel card on Teams that shows the address book from the 365.  However it also shows the admin accounts.  Currently, I got to hide the admin account using another card however I want to exclude those from the carousel all together:   

nk1ng_7-1631289222965.png

nk1ng_3-1631285755039.png

 

I am struggling with the code.  I know somewhere I need to have the IF statement here not the addressBookCard but I am stuck with the syntax:

   # addressBook(resultArrObj)
   [Activity
     name = Global
     Attachments = ${foreach (resultArrObj, x, json(addressBookCard(x))) }
     AttachmentLayout = carousel
   ]
 
Currently:
Attachment-> (bob's card #1), (hidden admin bob's card #2), (bob's card #3) with the if statement on addressBookCard
Need to have:
Attachment-> (bob's card #1), (bob's card #3) with the if statement in addressBook in theory anyways, if that makes sense?

Here is the whole bot responses code to understand what I am saying:

 

 

[import](common.lg)

> Begin AddressBook
#addressBookCard(resultObj)
-IF: ${ contains(resultObj.mailNickname,'admin') }
- ```
{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.2",
    "body": [
        {
            "type": "Container",
            "items": [
                {
                    "type": "TextBlock",
                    "text": "Hidden Account",
                    "wrap": true,
                    "horizontalAlignment": "Center",
                    "weight": "Lighter",
                    "color": "Accent",
                    "isSubtle": true,
                    "height": "stretch"
                }
            ],
            "height": "stretch",
            "minHeight": "230px",
            "verticalContentAlignment": "Center"
        }
    ]
}
```
- ELSE:
- ```
{
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "type": "AdaptiveCard",
    "version": "1.2",
    "body": [
        {
            "type": "ColumnSet",
            "columns": [
                {
                    "type": "Column",
                    "width": "auto",
                    "items": [
                        {
                            "type": "Image",
                            "size": "Stretch",
                            "url": "https://redacted.sharepoint.com/_layouts/15/userphoto.aspx?size=S&username=${resultObj.Mail}",
                            "style": "Person",
                            "selectAction": {
                                "type": "Action.OpenUrl",
                                "url": "https://redacted.sharepoint.com/_layouts/15/userphoto.aspx?size=S&username=${resultObj.Mail}"
                            },
                            "width": "60px",
                            "height": "60px"
                        }
                    ]
                },
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "${resultObj.displayName} (${resultObj.mailNickname})",
                            "horizontalAlignment": "Right",
                            "isSubtle": true,
                            "wrap": true,
                            "size": "Large",
                            "fontType": "Default",
                            "weight": "Bolder"
                        },
                        {
                            "type": "TextBlock",
                            "text": "${resultObj.jobTitle}",
                            "horizontalAlignment": "Right",
                            "spacing": "None",
                            "size": "Medium",
                            "color": "Accent",
                            "wrap": true
                        }
                    ],
                    "height": "stretch"
                }
            ]
        },
        {
            "type": "ColumnSet",
            "separator": true,
            "spacing": "Medium",
            "columns": [
                {
                    "type": "Column",
                    "width": "stretch",
                    "items": [
                        {
                            "type": "TextBlock",
                            "text": "${resultObj.department}",
                            "horizontalAlignment": "Right",
                            "height": "stretch"
                        },
                        {
                            "type": "TextBlock",
                            "text": "${resultObj.City}",
                            "horizontalAlignment": "Right",
                            "spacing": "Small",
                            "height": "stretch"
                        },
                        {
                            "type": "TextBlock",
                            "text": "${resultObj.OfficeLocation}",
                            "horizontalAlignment": "Right",
                            "spacing": "Small",
                            "height": "stretch"
                        },
                        {
                            "type": "TextBlock",
                            "text": "${resultObj.Mail}",
                            "wrap": true,
                            "horizontalAlignment": "Right",
                            "spacing": "Small"
                        },
                        {
                            "type": "TextBlock",
                            "text": "${resultObj.BusinessPhones}",
                            "wrap": true,
                            "spacing": "Small",
                            "horizontalAlignment": "Right"
                        },
                        {
                            "type": "TextBlock",
                            "text": "${resultObj.mobilePhone}",
                            "horizontalAlignment": "Right",
                            "spacing": "Small",
                            "height": "stretch"
                        }
                    ]
                }
            ]
        },
        {
            "type": "Container",
            "separator": true,
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "Column",
                            "width": "auto",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "wrap": true
                                }
                            ]
                        }
                    ],
                    "isVisible": false
                }
            ]
        }
    ]
}
```

# addressBook(resultArrObj)
[Activity
name = Global
Attachments = ${foreach (resultArrObj, x, json(addressBookCard(x))) }
AttachmentLayout = carousel
]
# SendActivity_k1Z42T()
- ${addressBook(dialog.resultArrObj)}

 


and here an redacted JSON that I am passing through to SendActivity:

 

[
  {
	  "Id":"xxxxxxx-xxx-xxxx-xxxx-redacted",
	  "AccountEnabled":true,
	  "BusinessPhones":"1-555-555-5555",
	  "City":"Redacted",
	  "CompanyName":"Redacted",
	  "Department":"IT Dept",
	  "DisplayName":"Bob Smith",
	  "GivenName":"Bob",
	  "JobTitle":"Principal, IT Dept",
	  "Mail":"Bob.Smith@redacted.com",
	  "MailNickname":"bobsmith",
	  "mobilePhone":"1-555-555-5555",
	  "OfficeLocation":"01.01 Redacted",
	  "PostalCode":"55555",
	  "Surname":"Smith",
	  "TelephoneNumber":"1-555-555-5555",
	  "UserPrincipalName":"Bob.Smith@redacted.com"
  },
  {
	  "Id":"xxxxxxx-xxx-xxxx-xxxx-redacted",
	  "AccountEnabled":true,
	  "BusinessPhones":"",
	  "City":"Redacted",
	  "CompanyName":"Redacted",
	  "Department":"IT Dept",
	  "DisplayName":"Bob Smith (Admin O365)",
	  "GivenName":"Bob",
	  "JobTitle":"Principal",
	  "Mail":"bobsmithadmin@redacted.onmicrosoft.com",
	  "MailNickname":"bobsmithadmin",
	  "mobilePhone":"1-555-555-5555",
	  "OfficeLocation":"01.01 Redacted",
	  "PostalCode":"55555",
	  "Surname":"Smith",
	  "TelephoneNumber":"1-555-555-5555",
	  "UserPrincipalName":"bobsmithadmin@redacted.onmicrosoft.com"
  },
  {
	  "Id":"xxxxxxx-xxx-xxxx-xxxx-redacted",
	  "AccountEnabled":true,
	  "BusinessPhones":"1-555-555-5555",
	  "City":"Redacted",
	  "CompanyName":"Redacted",
	  "Department":"IT Dept",
	  "DisplayName":"Bob Smith",
	  "GivenName":"Bob",
	  "JobTitle":"Principal, IT Dept",
	  "Mail":"Bob.Smith@redacted.com",
	  "MailNickname":"bobsmith",
	  "mobilePhone":"1-555-555-5555",
	  "OfficeLocation":"01.02 Redacted",
	  "PostalCode":"55555",
	  "Surname":"Smith",
	  "TelephoneNumber":"1-555-555-5555",
	  "UserPrincipalName":"Bob.Smith@redacted.com"
  }
]

 

 

Let me know and if you can help!
1 ACCEPTED SOLUTION

Accepted Solutions
Expiscornovus
Dual Super User
Dual Super User

Hi @nk1ng,

 

I still have to figure out how we can do this in code.

 

However, looking at your previous threads you are using a search for users action in Power Automate flow, correct?

 

If so, you could use this filter array action in the flow to exclude the admin accounts from your array.

 

nicknamedoesnotendwithadmin.png

View solution in original post

3 REPLIES 3
Expiscornovus
Dual Super User
Dual Super User

Hi @nk1ng,

 

I still have to figure out how we can do this in code.

 

However, looking at your previous threads you are using a search for users action in Power Automate flow, correct?

 

If so, you could use this filter array action in the flow to exclude the admin accounts from your array.

 

nicknamedoesnotendwithadmin.png

nk1ng
Helper II
Helper II

Thank you so much, Expiscornvus!  Works perfectly except when I try cast into a string, I get the original array?

nk1ng_0-1631541086866.png

 

 

nk1ng
Helper II
Helper II

Nevermind, just needed to grab from the body('Filter_array').

nk1ng_1-1631541438720.png

 

Thank you again!

-n

Helpful resources

Announcements
Canadian Cloud 2022 768x460.png

Register for a free PVA chatbot creation workshop.

Learn how to respond rapidly to your customers and employees at scale, using intelligent conversational chatbots.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Users online (3,554)