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

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Extracting data from a service

AV_10867476
10-Marble

Extracting data from a service

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 2

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

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

 

Announcements


Top Tags