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 / Power Apps / How I can get data at ...
Power Apps
Unanswered

How I can get data at Client side with Javascript?

(0) ShareShare
ReportReport
Posted on by 264

Hello!

I need to get data from Dataverse at Client side? Is there a way to do it? If it is possible give me the example or link pls.

I there a way to save data to Dataverse?

I have the same question (0)
  • ChrisPiasecki Profile Picture
    6,422 Most Valuable Professional on at

    Hi @Max77,

     

    Is the client an external JavaScript application outside of the Power Platform? Or are you referring to using JavaScript inside of the model driven application?

     

    If it's an external application, you can try out the single page app sample which uses MSAL.js library to help authenticate.

     

    If you want to use JavaScript inside of your model driven app such as in a form, you would want to leverage a JavaScript web resource that uses the Dataverse Client (JavaScript) API.

     

    ---
    Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

  • Max77 Profile Picture
    264 on at

    @ChrisPiasecki , Yes I asked about "inside model driven app". 

    In model driven app I can manage a form - set hide or read only for attributes and have access to values in the form, but what about other Dataverse data? another Entity (table)?

     

    I have found a way with OData.

    {
     var uniqueNotificationId = "OutstandingTasks"; 
     
     Xrm.Page.ui.clearFormNotification(uniqueNotificationId);
     
     var contactId = Xrm.Page.data.entity.getId().replace(/[{}]/g,"");
     var currentUserId = Xrm.Page.context.getUserId().replace(/[{}]/g,"");
     
     var req = new XMLHttpRequest();
     var requestUrl = Xrm.Page.context.getClientUrl() + "/api/data/v8.2/tasks?$filter=_regardingobjectid_value eq " + contactId + " and _ownerid_value eq " + currentUserId + " and statecode eq 0";
     
     req.open("GET", requestUrl, true);
     req.setRequestHeader("OData-MaxVersion", "4.0");
     req.setRequestHeader("OData-Version", "4.0");
     req.setRequestHeader("Accept", "application/json");
     req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
     req.onreadystatechange = function () {
     if (this.readyState === 4) {
     req.onreadystatechange = null;
     if (this.status === 200) {
     var results = JSON.parse(this.response);
     
     if(results.value.length > 0){
     Xrm.Page.ui.setFormNotification("You have outstanding tasks assigned to you.", "WARNING", uniqueNotificationId)
     } 
     }
     else {
     //.. handle error
     }
     }
     };
     req.send();
    } 

     

    But OData is an obsolete way. I'd like to use SQL query, is it possible?

  • Verified answer
    ChrisPiasecki Profile Picture
    6,422 Most Valuable Professional on at

    Hi @Max77,

     

    As I mentioned previously, you can use the Dataverse Client API, the Xrm.WebApi namespace is an abstraction that uses the OData web api without having to construct raw XmlHttRequest yourself. 

     

    There is no direct access to the Dataverse database via SQL. All requests go through the Dataverse Web API.

     

    ---
    Please click Accept as Solution if my post answered your question. This will help others find solutions to similar questions. If you like my post and/or find it helpful, please consider giving it a Thumbs Up.

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 > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard