Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Example of Get Method using safe ajax method in power pages

Posted on by 15

I want to get the contact records using click of button in web page power portal

  • Suggested answer
    Eiken Profile Picture
    Eiken on at
    RE: Example of Get Method using safe ajax method in power pages

    Hi,

    You can also use liquid to return JSON or XML.

    Please check the following links. It may help you.

    How to get a record from Dataverse via Javascript in Power Portal? - Microsoft Dynamics CRM Forum Community Forum

    Dynamics 365 portals: Use liquid to return JSON or XML – Colin Vermander (wordpress.com)

  • Suggested answer
    Eiken Profile Picture
    Eiken on at
    RE: Example of Get Method using safe ajax method in power pages

    Hi,

    Firstly add a custom button in the form using Js code.

    pastedimage1676616179089v1.png

    Then you can edit the Js code for the button and send ajax request.

    $(document).ready(function(){
    AddCloseButton();
    $('.btn-geyInf').bind('click',function(){
    var req = new XMLHttpRequest();
    req.open("GET", (Enter the interface here), true);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function() {
    if (this.readyState === 4) {
    req.onreadystatechange = null;
    if (this.status === 200) {
    var results = JSON.parse(this.response);
    console.log(results.value);
    } else {
    Xrm.Utility.alertDialog(this.statusText);
    }
    }
    };
    req.send();
    })
    });
    function AddCloseButton(){
    var button ="<input type='button' class='btn btn-geyInf' value='Get Contact Inf'/>"
    $("#EntityFormControl_862039e46daeed11aad1000d3a314363_EntityFormView").next().append(button);
    };


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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans