Page 1 of 1

Update Field automatically

Posted: 08 Feb 2017
by TWendt
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

Re: Update Field automatically

Posted: 08 Feb 2017
by Dmitry Kozlov
Not sure I undertood what Save button you mean. Do you use the related items in the quick edit mode?

Re: Update Field automatically

Posted: 08 Feb 2017
by TWendt
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

Re: Update Field automatically

Posted: 09 Feb 2017
by Dmitry Kozlov
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.

Re: Update Field automatically

Posted: 10 Feb 2017
by TWendt
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

Re: Update Field automatically

Posted: 13 Feb 2017
by Dmitry Kozlov
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"]

Re: Update Field automatically

Posted: 15 Feb 2017
by TWendt
Hi Dmitry,

thanks, it works now.

Best wishes

Tom