Update Field automatically
Posted by TWendt - Feb 8 ’17 at 02:59
Hi all,
i calculate the Software costs from a related items lists with javascript. For example
var total = 0;
var rows = fd.relatedItems(5).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item['Kosten.'])
});
fd.field('Kosten_x0020_Software').value(total);
If i add a new row in the related items list i must press save two times to update the field "Kosten". Is it possible to update the field automatically?
Best wishes
Tom
-
Dmitry KozlovAdminMember for: 9 years 8 months 7 days
Not sure I undertood what Save button you mean. Do you use the related items in the quick edit mode?
-
TWendtMemberMember for: 8 years 8 months 20 days
Hi Dmitry,
i have a calculated field named "costs total" where the costs from the field hardware, software, maintenance are sum up. If i press the save button the field "costs total" is not updated. I must open the form again and if i press save again, the field is updated.
What must i do?
Best wishes
Tom
-
Dmitry KozlovAdminMember for: 9 years 8 months 7 days
[#2]: The code you use looks right, it should updata the total immidiately after adding/removing rows. Just replace this:
fd.field('Kosten_x0020_Software').value(total);
with
fd.field('Kosten_x0020_Software').control()._el().html(total);
If it does not help, I recommend you to purchase 100 support minutes and provide temporary access to your form.
-
TWendtMemberMember for: 8 years 8 months 20 days
Hi Dmitry, many thanks, it works. But one question, is it possible to sum this five fields (Bold) to a field named total costs?
For example:
Three sum fields (Hardware, Software and Maintenance) filled by javascript.
var total = 0;
var rows = fd.relatedItems(5).data('ctx').ListData.Row;
rows.forEach(function(item) {
total += parseFloat(item['Kosten.'])
});
fd.field('Kosten_x0020_Software').control()._el().html(total);
and two calculated fields (Internal programming and User training) filled by a sharepoint formula
=[Number of days]*500
Best wishes
Tom
-
Dmitry KozlovAdminMember for: 9 years 8 months 7 days
[#4]: You can use the same forumula in JavaScript and calculate a field value dynamically. Or probably, you can get a calcualte value like other field values: fd.relatedItems(5).data('ctx').ListData.Row[0]["CalcField"]
-
TWendtMemberMember for: 8 years 8 months 20 days
Hi Dmitry,
thanks, it works now.
Best wishes
Tom