cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Translate the entire conversation x

how to pass dynamic value for datatable columns

AP_9467111
5-Regular Member

how to pass dynamic value for datatable columns

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? 

 

ACCEPTED SOLUTION

Accepted Solutions
TonyZhang
15-Moonstone
(To:AP_9467111)

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 */
});

Tony

View solution in original post

2 REPLIES 2
TonyZhang
15-Moonstone
(To:AP_9467111)

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 */
});

Tony
TonyZhang
15-Moonstone
(To:AP_9467111)

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

Tony
Announcements


Top Tags