Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

relation between invoice entity with account entity through customer field in invoice entity

Posted on by Microsoft Employee

how to calculate the sum of total amount of invoices for a particular customer. where total amount and customer are a fields in one invoice. customer field have lookup of names of account entity  using javascript code and rest query in dynamic crm online

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: relation between invoice entity with account entity through customer field in invoice entity

    after taking a rollup field sum in account entity when we put the value in total amount in invoice the rollup field is not updated automatically,it updated when we refresh on the sum field.

      I want the the total amount of particular customer is not greater than credit limit using javascript in web resources and rest query .

    total amount field in invoice entity and credit limit field in account entity

    I work but my code is not work  can anyone guide me.

    function limit(){

    var CustomerGUID = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts("+CustomerGUID.slice(1,-1)+")?$select=creditlimit", 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 result = JSON.parse(this.response);

               var creditlimit = result["creditlimit"];

               var creditlimit_formatted = result["creditlimit@OData.Community.Display.V1.FormattedValue"];

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    var req = new XMLHttpRequest();

    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts?$select=name,pre_sum", 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);

               for (var i = 0; i < results.value.length; i++) {

                   var name = results.value[i]["name"];

                   var pre_sum = results.value[i]["pre_sum"];

                   var pre_sum_formatted = results.value[i]["pre_sum@OData.Community.Display.V1.FormattedValue"];

    if(CustomerGUID ==name)

    {

    if(creditlimit>pre_sum)

    {

    alert("not entered");

    }

          }

           } else {

               Xrm.Utility.alertDialog(this.statusText);

           }

       }

    };

    req.send();

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: relation between invoice entity with account entity through customer field in invoice entity

    ok I understood what u say.

    Thanks David Jennaway

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: relation between invoice entity with account entity through customer field in invoice entity

    This is a good idea.

    Thanks PekkaSahlsten

  • Suggested answer
    PekkaSahlsten Profile Picture
    PekkaSahlsten 827 on at
    RE: relation between invoice entity with account entity through customer field in invoice entity

    Create a rollup field "Sum of Invoices" (or similar) on the account entity form:

    6445.Capture.PNG

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: relation between invoice entity with account entity through customer field in invoice entity

    In which field I use rollup . Both field are not custom field.

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: relation between invoice entity with account entity through customer field in invoice entity

    Rather than using code, you could use a rollup field for this

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