DarthCSharper
DarthCSharper

Reputation: 133

D365 New Button creates price line with empty line

After adding logic about creating price for object in grid it's always created "one line more" which is empty. So, if there is need to be created two lines, it will be created 3 lines and that one addition will be empty.

Is there something what I missing in code?

   [Control("CommandButton")]
    class AreaActionPaneNew
    {
        void clicked()
        {
            PMCParameters   contractParameters = PMCParameters::find();
            PMETmpRentalObjectArea  groupedAreaList; // Group by area_type and cost_type
            PMERentalObjectPrice    priceList;
            date workingDate = currWorkingDate.dateValue();
            ;
            super();

            // Get grouped area values. Values are summed up by area_type and ancost_type
            groupedAreaList = PMERentalObjectAreaCl::getRentalAreaPrCostType(pmeRentalobject.RentalObjectId, userSetting.validFrom(), userSetting.validTo() , workingDate);

            ttsbegin;
            while select groupedAreaList
            {
                select forupdate firstonly priceList
                    where priceList.RentalObjectId == pmeRentalObject.RentalObjectId &&
                          priceList.RentalCostType == groupedAreaList.RentalCostTypeId &&
                          priceList.AreaType == groupedAreaList.Areatype && priceList.ValidFrom == pmeRentalObject.ValidFrom;

                if (!priceList)
                    priceList.initValue();

                priceList.RentalObjectId = pmeRentalObject.RentalObjectId;
                priceList.RentalCostType = groupedAreaList.RentalCostTypeId;
                priceList.ValidFrom      = pmeRentalobject.ValidFrom;

                priceList.AreaType       = groupedAreaList.Areatype;


   priceList.Amount         = groupedAreaList.Price;
            priceList.Area           = groupedAreaList.AreaValue;
            priceList.Quantity       = groupedAreaList.RentalQty;

            if (!priceList)
                priceList.Period  = contractParameters.ReportPeriod;

            if (priceList)
                priceList.update();
            else
                priceList.insert();
        }
        ttscommit;

        pmeRentalObjectPrice_ds.research();
    }

}

Upvotes: 1

Views: 198

Answers (1)

Alex Kwitny
Alex Kwitny

Reputation: 11544

The code looks like it only updates/inserts without creating a blank line.

From your attribute, you are using a Command Button (see here), which may have an associated command, such as New, which effectively pushes Ctrl+N, and would explain why you have a blank line.

The simplest way to check is just create a regular Button and override the clicked method, then copy/paste your code and push both buttons and see if they have different behavior.

Check the Command property on the button and see if there's something there. Try commenting out the super(); call.

You should perhaps consider just a Button or a Menu Item Button with an associated object.

Upvotes: 1

Related Questions