Skip to main content

Notifications

Announcements

No record found.

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

Error in script for calculating product quantity in editable subgrid

Posted on by 10

Description:

I am having trouble with a script that is supposed to calculate the quantity of a product in an editable subgrid in the quote form in Dynamics 365 Sales. The script is triggered by an OnChange event on the "number of pieces" field in the subgrid and is supposed to calculate the product quantity based on the number of pieces and the unit volume of the product.

The script I am using is:

function CalcQdt(context){ var pecas = (context.getFormContext().data.entity).attributes.getByName("cr452_quantidadedepecas"); var VolUn =(context.getFormContext().data.entity).attributes.getByName("cr452_volumeun"); var QDT =(context.getFormContext().data.entity).attributes.getByName("quantity"); if (pecas != null && VolUn != null) { var pecas = pecas.getValue(); var VolUn = VolUnField.getValue(); var quantity = pecas * VolUn; quantityField.setValue(quantity); } }

However, when I make changes to the "number of pieces" field, nothing happens. I have checked the code and there are no syntax errors. Can anyone help me figure out what is going wrong with this script?

  • Suggested answer
    NODAL Profile Picture
    NODAL 860 on at
    RE: Error in script for calculating product quantity in editable subgrid

    Hi Felipedcs,

    Your script has some refernce issues. (you have initialized quantity Field as QDT and while setting using as quantityField)

    Refer corrected code below.

    function CalcQdt(context) {
      var pecas = context
        .getFormContext()
        .data.entity.attributes.getByName("cr452_quantidadedepecas");
      var VolUn = context
        .getFormContext()
        .data.entity.attributes.getByName("cr452_volumeun");
      var QDT = context
        .getFormContext()
        .data.entity.attributes.getByName("quantity");
      if (pecas != null && VolUn != null) {
        var pecas = pecas.getValue();
        var VolUn = VolUnField.getValue();
        var quantity = pecas * VolUn;
        QDT.setValue(quantity);
      }
    }

    Cheers,

    Ketan

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