Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / Example of Get Method ...
Sales forum
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

Categories:
  • 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);
    };


Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

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

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,277 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,126 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans