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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / Run piece of javascrip...
Copilot Studio
Unanswered

Run piece of javascript code to hide chat bot elements

(1) ShareShare
ReportReport
Posted on by 101
Hello,
 
 
To hide chat history I've integrated "End Chat" button. Now on click of it I'm calling specific Topic now I would like to execute specific javascript code which will hide all elements of previous chat. So how can I execute javascript code from Copilot agent topic?
 
var divsToHide = document.getElementsByClassName("webchat__basic-transcript__activity webchat__basic-transcript__activity--acknowledged webchat__basic-transcript__activity--read"); //divsToHide is an array
    for(var i = 0; i < divsToHide.length; i++){
        divsToHide[i].style.visibility = "hidden"; // or
        divsToHide[i].style.display = "none"; // depending on what you're doing
    }
 
 
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Vinoth Selvam Profile Picture
    1,590 Super User 2025 Season 2 on at
     
    You will not be able to directly execute a Javascript code.
     
    If your JavaScript logic can be encapsulated in a server-side API or webhook, you can call it using the HTTP Connector in Power Automate and integrate it into your Copilot Studio bot.
    You can also use Azure Logic Apps with the Inline Code action to run JavaScript code and return results. You can call Logic Apps from Copilot Studio using HTTP actions or Power Automate.
     
    Thanks.
  • Suggested answer
    Artur Stepniak Profile Picture
    1,539 Super User 2025 Season 2 on at
    Hello Jignesh,
     
    I see that you're fighting with it. ;-) Vinoth solution won't work, because you'd need to inject the JS script in the DOM. There's no option to invoke any scripts from within an adaptive card. The only option that I see to try out is to prepare a separate button outside the chat window and add the code that you've provided. I'm not sure though if it'll work properly - you're hiding the elements, wouldn't it be better to reinstantiate the chat bubble instead? Otherwise, you'd clutter the website with hidden elements.
     
    In case of any other questions, let me know. If the answer helped you, mark it, so that others can benefit from it.
     
    Best regards,
     
    Artur Stepniak
    Interested in GenAI? Visit my site!
  • Jignesh Patel Profile Picture
    101 on at
    Hi
     
    I integrated @Vinoth Selvam solution to add Javascript code using Logic app but it is not working as expected.
    @Artur Stepniak Could you plz guide how can I reinitiate conversation but would like to hide previous history.
     
    Thanks
  • Suggested answer
    Artur Stepniak Profile Picture
    1,539 Super User 2025 Season 2 on at
    Hello,
     
    the best way would be to remove the chat bubble from the DOM and add it again. That way you'll get a new fresh chat.
     
    In case of any other questions, let me know. If the answer helped you, mark it, so that others can benefit from it.
     
    Best regards,
     
    Artur Stepniak
    Interested in GenAI? Visit my site!
  • Jignesh Patel Profile Picture
    101 on at
    Thank you@Artur Stepniak ,
     
    That is what I would like to know how can I remove the chat bubble and add it again. Could you plz guide me.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Copilot Studio

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 255 Super User 2025 Season 2

#2
Romain The Low-Code Bearded Bear Profile Picture

Romain The Low-Code... 205 Super User 2025 Season 2

#3
S-Venkadesh Profile Picture

S-Venkadesh 101 Moderator

Last 30 days Overall leaderboard