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

unsaved changes after calling a form

(0) ShareShare
ReportReport
Posted on by 160

Hi all,

 I have following JavaScript on Quote Form and I have added it on Change of "Pre-Freight Amount" and Onload and On Save on the Form: The code calculate the Total tax and Total Amount, if a Discount is added:

function CalculateTax(executionContext){

    var formContext = executionContext.getFormContext();
    var preFreight = formContext.getAttribute('totalamountlessfreight').getValue();
    var tax = formContext.getAttribute("tv_tax").getText();
    var total = formContext.getAttribute('tv_totalamounts').getValue();
    var total_tax = formContext.getAttribute("tv_totaltax").getValue();

    var percent = parseFloat(tax);
debugger;
    
    if (tax != "" && tax != null){

        var Discount = preFreight * percent/100;
        
        formContext.getAttribute("tv_totaltax").setValue(parseFloat(eval(Discount)));
        formContext.getAttribute('tv_totaltax2').setValue(Discount);
        var Amount = preFreight + formContext.getAttribute("tv_totaltax").getValue();
        formContext.getAttribute('tv_totalamounts').setValue(Amount);
        formContext.getAttribute('totalamount').setValue(Amount);

    }
    else {
        formContext.getAttribute("tv_totaltax").setValue(parseFloat(eval(0)));
        formContext.getAttribute('tv_totaltax2').setValue(0);
        

    }


}

pastedimage1605088917510v1.png

But after changing the Discount amount in Discount percent or Discount field, the changes remains unsaved on the Form.

could somebody tell me, what could be the reason of that?

Many Thanks

  • Suggested answer
    Gilmeyer Profile Picture
    on at
    RE: unsaved changes after calling a form

    Hi,

    Please use docs.microsoft.com/.../save after running your logic so that it gets saved.

  • Joana Pinto Profile Picture
    740 on at
    RE: unsaved changes after calling a form

    Hi,

    First, do you really need to call that js on those 3 events? It isn't enough to call on onLoad and onChange?

    Second, you are not saving the form actually. You are just setting the value. So I think you need to do a formContext.data.save() to see your changes saved.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans