Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Sales forum / Error in script for ca...
Sales forum
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

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,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans