I have a lookup on a form where a user will select a Weekly Budget record. Once they select the record, it pulls the budget amount from the selected record and populates it to a field called Budget Amount on the form. I perform calculations (subtraction) on this form and then update the Budget Amount field with the new weekly budget value. My problem is that I am not able to successfully take that Budget Amount value and update it back to the original Weekly Budget record. My code runs alright, but the value is still the same. I tried looking for an example, but all the SDK examples show just setting a given value instead of setting it to a field's value.
Here is my code
// Update Weekly Budget value back to Weekly Budget record function updateWeeklyBudgetDetails(weeklybudgetId) { // Declare variables var budget = {}; var weeklyBudget = Xrm.Page.getAttribute("new_budgetamount").getValue(); var finalPledgeAmount = Xrm.Page.getAttribute("new_pledgeamt").getValue(); var updatedWeeklyBudget; // Subtract Final Pledge Amount for this Procedure and Set Updated Weekly Budget to that value updatedWeeklyBudget = weeklyBudget - finalPledgeAmount; Xrm.Page.getAttribute("new_budgetamount").setValue(updatedWeeklyBudget); budget.new_Amount = { Value: updatedWeeklyBudget }; // Set new Budget Amount; Budget Amount - Final Pledge Amount SDK.REST.updateRecord( weeklybudgetId, budget, "new_weeklybudget", function () { alert("The Weekly Budget record changes were saved"); }, errorHandler ); }
Any help is appreciated!