Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Custom Activities Javascript integration

(0) ShareShare
ReportReport
Posted on by 3

Hello, I'm a junior developer, and I'm trying to implement a functionality that aims to utilize user interactions with the website. For instance, if the user clicks on a specific product on the webpage, I want to trigger an activity in Dynamics that states /this user is interested in product X/. Is there a way to create something like this in Dynamics using JavaScript?
  • Verified answer
    Dengliang Li Profile Picture
    Dengliang Li Microsoft Employee on at
    Custom Activities Javascript integration
    Hi,
     
    You can send an XMLHTTPRequest to Powre Automate Flow by clicking on a specific product.
    A JSON string containing the product information is included in the sent request.
    Then create an activity in Power Automate Flow using the product information.
     
    In my testing, the flow is triggered when Product 1 is clicked.
    The source code is shown below.
     
    <div id="prodcut" style="height: 100px;width: 100px;border: 1px solid;">
            <p>Product1</p>
            <p>Product2</p>
            <p>Product3</p>
        </div>
    <script>
     
       var product =document.getElementsByTagName("p")[0];
       product.addEventListener("click",function(e){
            let data={"Product_Name":""};
           
            //Get the name of the product
            data.Product_Name = e.target.innerHTML;
            // This URL comes from the connector in the flow / when an HTTP request is received / generated URL.
            var  requrl = "<Your URL>"
            var req = new XMLHttpRequest();
            req.open("POST",requrl,true);
            req.setRequestHeader("Accept","application/json");
            req.setRequestHeader("OData-MaxVersion","4.0");
            req.setRequestHeader("OData-Version","4.0");
            req.setRequestHeader("If-None-Match","null");
            req.setRequestHeader("Content-Type","application/json ");
            req.send(JSON.stringify(data));
    </script>
     
    The Power Automate Flow is shown below.
    The HTTP POST URL is the request URL in the above code.
     
    Below are the links that can be referenced.
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me .
     
    Best Regards,
    Dengliang Li

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans