Change Value in the code (in places like value[i].Value and value[i].Value.replace(/$/g,'')) with the InternalName of the Total Sale Price column. You can check the InternalName in the designer, if you open the child form:
function calcTotal() {
var value = fd.control('{SPDataTable0}').widget.dataItems();
var total = 0;
if(value){
for (var i = 0; i < value.length; i++){
if(value[i].Value)
total += parseInt(value[i].Value.replace(/[^0-9.]/g, ""));
}
}
fd.field('Total').value = total;
}
var myVar = 0;
fd.spRendered(function() {
// disable the field
fd.field('Total').disabled = true;
//refreshing the total
var myVar = setInterval(calcTotal, 2000);
});
fd.spBeforeSave(function(spForm) {
var myVar = setInterval(calcTotal, 2000);
calcTotal();
clearInterval(myVar);
});
The line of code that attempts to get the table is returning an error: Cannot read property 'widget' of undefined
I have verified that I have the table name spelled correctly so I know I have that right.
Here is my code.
function calcTotal() {
var value = fd.control('{SPDataTable1}').widget.dataItems();
var total = 0;
if(value){
for (var i = 0; i < value.length; i++){
if(value[i].Value)
total += parseInt(value[i].Value.replace(/[^0-9.]/g, ""));
}
}
fd.field('Numeric1').value = total;
Please remove braces {} from the filed name. I've used them to highlight that the field name should be changed, now I think it was a bad idea
function calcTotal() {
var value = fd.control('SPDataTable1').widget.dataItems();
var total = 0;
if(value){
for (var i = 0; i < value.length; i++){
if(value[i].Value)
total += parseInt(value[i].Value.replace(/[^0-9.]/g, ""));
}
}
fd.field('Numeric1').value = total;
};
Hello,
This will give total of all records,
I want total of some particular records that have unique loginID field,
like just 4 or 5 records total that have loginID as abc@gmail.com
You can add any condition to the code to calculate totals only for specific records. For instance, the code below calculates the total price of records whose status is equal to 'active'.
function calcTotal() {
var value = fd.control('SPDataTable1').widget.dataItems();
var total = 0;
if(value){
for (var i = 0; i < value.length; i++){
if(value[i].Price && value[i].Status == 'active')
total += parseInt(value[i].Value.replace(/[^0-9.]/g, ""));
}
}
fd.field('Total').value = total;
};
Hello @Margo,
I am trying to pass data from parent form to child form, Here is Document that i was gone through,
In Parent Form its works completed fine, i can get UserID from Parent Form to child form,
But when i am using Edit in the parent form, i can not get value from parent to child,
I am useing SharePoint online,
Here is my code,
var parentForm = window.top.fd;
console.log(parentForm,"Parentform");
if (parentForm) {
//Set field values with the values from the parent on form load
fd.field('Myid').value = parentForm.field('Mylogin').value;
//disable mytumid
fd.field('Myid').disabled = true;
}
When I try to open child form in Parent Form 'New', is shows console as below Screenshot,
but in Parent form 'Edit', it shows as undefine.