web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Error in script for calculating product quantity in editable subgrid

(0) ShareShare
ReportReport
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?

I have the same question (0)
  • Suggested answer
    NODAL Profile Picture
    860 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans