Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
Iam checking each row of datatable in for loop.
So iam using code: resultDT.rows[i].XXXXX
I stored the field definitions in array arr[] inside the same service. I want to pass them dynamically inside for loop to the code resultDT.rows[i].XXXXX . I dont want to hardcode them again. How to make this possible?
Solved! Go to Solution.
Hi @AP_9467111,
Please find below sample code to see if that gives you some clues.
// Suppose you have arrays contain data for each column.
let column1Array = ["a","b","c","d"],
column2Array = ["e","f","g","h"];
// Create Infotable from DataShape
let infotable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "SampleDataShape"
});
// Loop through the first array
column1Array.forEach(e => {
// create new entry in Json format
let newEntry = {
Column1: e,// STRING [Primary Key]
Column2: undefined// STRING
};
// add entry to Infotable
infotable.AddRow(newEntry);
});
// update rest columns of each infotable row
infotable.rows.toArray().forEach((row, index) => {
row.Column2 = column2Array[index];
});
// add infotable entries to datatable
me.AddOrUpdateDataTableEntries({
sourceType: undefined /* STRING */,
values: infotable /* INFOTABLE */,
location: undefined /* LOCATION */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
});
Hi @AP_9467111,
Please find below sample code to see if that gives you some clues.
// Suppose you have arrays contain data for each column.
let column1Array = ["a","b","c","d"],
column2Array = ["e","f","g","h"];
// Create Infotable from DataShape
let infotable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "SampleDataShape"
});
// Loop through the first array
column1Array.forEach(e => {
// create new entry in Json format
let newEntry = {
Column1: e,// STRING [Primary Key]
Column2: undefined// STRING
};
// add entry to Infotable
infotable.AddRow(newEntry);
});
// update rest columns of each infotable row
infotable.rows.toArray().forEach((row, index) => {
row.Column2 = column2Array[index];
});
// add infotable entries to datatable
me.AddOrUpdateDataTableEntries({
sourceType: undefined /* STRING */,
values: infotable /* INFOTABLE */,
location: undefined /* LOCATION */,
source: undefined /* STRING */,
tags: undefined /* TAGS */
});
Hi @AP_9467111,
If you feel your question has been answered, please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.
Regards,
Tony