Skip to main content

Notifications

Copilot Studio - General
Answered

Use an if statement to change a picture/ image in a chatbot

Posted on by 109

Hi there,

I have my data from a Sharepoint list. In one of the columns the value could be sometimes a "car" or a truck.

 

Now in my adaptive card I have an image inserted id = imgTransportMode.

 

What I need is to change the icon  depending on the value in my Share point column if the column shows car: insert the URl....car.png

if the SharePoint column value is truck: show the truck.png.

I don't know if this question should be posted in the PA forum ?

Sorry, very new to PVA.

 

Thanks 

Categories:
  • sajarac Profile Picture
    sajarac 109 on at
    Re: Use an if statement to change a picture/ image in a chatbot

    Thank you very much for your help.

    Yes. This part solve the issue:

    "url": "@{if(equals(body('Get_items')['value'][0]['AutoType/Value'], 'Car'), 'https://www.iconpacks.net/icons/1/free-car-icon-1057-thumb.png', 'https://www.iconpacks.net/icons/1/free-truck-icon-1058-thumb.png')}"

     

    Many thanks

     

    🙂

  • Verified answer
    Expiscornovus Profile Picture
    Expiscornovus 1,708 on at
    Re: Use an if statement to change a picture/ image in a chatbot

    Hi @sajarac,

     

    Apologies, I was confused with the expression language in the Bot Framework Composer topics.

     

    For adaptive cards within Power Automate cloud flows you could simply use the Power Automate expression language.

     

    Below is an example of that.

    In this example I use a title (which has the car name) column of a the first item of a SharePoint list and the AutoType choice field value (it can be either Car or Truck) of that same item. These are retrieved via a Get Items action.

     

    Within the image control I check if the value equals Car. If that is true I show a Car icon, otherwise a Truck icon.

     

     

     

     

    {
     "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
     "type": "AdaptiveCard",
     "version": "1.0",
     "body": [
    { 
     "type": "TextBlock",
     "text": "@{body('Get_items')['value'][0]['Title']}",
     "wrap": true
     },
     {
     "type": "TextBlock",
     "id": "acAutoType",
     "text": "@{body('Get_items')['value'][0]['AutoType/Value']}",
     "wrap": true
     },
     {
     "type": "Image",
     "url": "@{if(equals(body('Get_items')['value'][0]['AutoType/Value'], 'Car'), 'https://www.iconpacks.net/icons/1/free-car-icon-1057-thumb.png', 'https://www.iconpacks.net/icons/1/free-truck-icon-1058-thumb.png')}"
     }
     ],
     "spacing": "None"
    }

     

     

     

     

  • sajarac Profile Picture
    sajarac 109 on at
    Re: Use an if statement to change a picture/ image in a chatbot

    Hello @Expiscornovus , and thank you very much. I didn't know about the expression language. 

     

    I hope this part give you an idea:

     

    {
    "type": "Column",
    "spacing": "Small",
    "verticalContentAlignment": "Center",
    "items": [
    {
    "type": "Image",
    "height": "40px",
    "id": "LblIconCarorTruck",
    "size": "Medium",
    "url": "https://........../Car or Truck .png",
    "width": "40px"
    }
    ],
    "width": "auto"
    },
    {

  • Expiscornovus Profile Picture
    Expiscornovus 1,708 on at
    Re: Use an if statement to change a picture/ image in a chatbot

    Hi @sajarac,

     

    Adaptive cards has it's own expression language. You could try and use that in your adaptive card code.

    https://docs.microsoft.com/en-us/azure/bot-service/adaptive-expressions/adaptive-expressions-prebuilt-functions?view=azure-bot-service-4.0

     

    It could be an expression like below:

    "${if(equals(SharePointColumn,car), 'car.png', 'truck.png')}"
    

     

    Can you share the code of your current adaptive card? I might be able to adapt my example to your setup.

Helpful resources

Quick Links

Exciting News for Copilot Studio Communi…

Get ready to experience a whole new level of engagement with the Copilot Studio…

Celebrating the May Super User of the…

LaurensM is an exceptional contributor to the Power Platform Community…

Check out the Copilot Studio Cookbook…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
renatoromao Profile Picture

renatoromao 6,459

#2
Pstork1 Profile Picture

Pstork1 1,997

#3
Expiscornovus Profile Picture

Expiscornovus 1,708

Leaderboard