Data Table (SpDataTable0) concatenate column values based on criteria

Hello,

i have form with a sub form Data Table (SpDataTable0)

when data table (SpDataTable0) change i need to concatenate column values based on other column value.

i will concatenate all values from column01 where column02 == true and set control01 on main form equal those concatenated values
same i will concatenate all values from column01 where column02 == false and set control02 on main form equal those concatenated values

like:
fd.field("control01").value = concatenated value from column01 where column02 === true;
fd.field("control02").value = concatenated value from column01 where column02 === false;

my data table (SpDataTable0) edited in dialogue mode not inline.

kindly how to achieve this on change (edit, delete, add) each time i need to check the hole data table and re-enter new concatenated values.

Find attached a screenshot with more details:

Hello @gkhadra,

Please see below the example of the code which concatenates values from the 'List or Library' control and updates the field in the form.

Please replace field names in the code with the fields internal names.

function concatText() {

var value = fd.control('SPDataTable0').widget.dataItems();
var text = "";
if(value){
    for (var i = 0; i < value.length; i++){
        if(value[i].column01 && value[i].column02 === "true")
          text += value[i].column01;
    }
}
fd.field('control01').value = text;
}
var myVar = 0;

fd.spRendered(function() {

//refreshing the result
var myVar = setInterval(concatText, 2000);

}); 

fd.spBeforeSave(function(spForm) {
    var myVar = setInterval(concatText, 2000);
    concatText();
    clearInterval(myVar);
});
1 Like

Thank you a lot superb.

Kindly my first column (column01) is Lookup
How can i get the lookupValue not ID in order to concatenate

@gkhadra,

To get Lookup value from 'List or library' control the syntax should be

fd.control('SPDataTable0').widget.dataItems()[0].ColumName[0].lookupValue;

So in your case, the code will be as follows.

function concatText() {

var value = fd.control('SPDataTable0').widget.dataItems();
var text = "";
if(value){
    for (var i = 0; i < value.length; i++){
        if(value[i].column01 && value[i].column02 === "true")
          text += value[i].column01[0].lookupValue;
    }
}
fd.field('control01').value = text;
}
var myVar = 0;

fd.spRendered(function() {

//refreshing the result
var myVar = setInterval(concatText, 2000);

}); 

fd.spBeforeSave(function(spForm) {
    var myVar = setInterval(concatText, 2000);
    concatText();
    clearInterval(myVar);
});
1 Like