Skip to main content
10-Marble
February 6, 2024
Question

Extracting data from a service

  • February 6, 2024
  • 2 replies
  • 695 views

I have created a service which takes an input by the name "objectData" and this is a data shape which has certain property and values like: 

rootCauses

0containmentActions

daysOpen

workflowStatus

stepStatusTable

supplierTeam

adjustedCloseDate

actionStatus

workItems

Here in the service what i want to do is that pick any property and manipulate the data which the property holds, since this input objectData is the output of some other service and is binded to as the input of this service for manipulation. So far i have tried this code but i think it's incorrect :

for(let i = 0; i< objectData.length; i++){
    let row = objectData.rows[i];
    if("workflowStatus" in row ){
        //increment some value or manipulate the row property
    }
}

2 replies

14-Alexandrite
February 6, 2024

@AV_10867476  teh input is an infotable or is a JSON object? Could you share a sample input.

Rocko
19-Tanzanite
February 6, 2024

Your code should work, if objectData is an infotable of the dataShape you described.

Here's a working sample:

// setting up a sample infotable using a system datashape
let it=DataShapes.RemoteServiceBinding.CreateValues();
it.AddRow({name:"aa",sourceName:"bb", timeout:1});
it.AddRow({name:"cc",timeout:2});
it.AddRow({name:"ee",sourceName:"ff", timeout:3});

// iterating and updating
for(let i = 0; i< it.length; i++){
 let row = it.rows[i];
 if("sourceName" in row ){
 row.timeout=99;
 }
}
//returning result infotable
result=it;

 

When iterating, I would prefer this notation for brevity, but yours is fine as well.

it.rows.toArray().forEach(row=>{
 if (row.sourceName) 
 row.timeout=99;
});