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

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Extracting property from infotable for comparision

AV_10867476
10-Marble

Extracting property from infotable for comparision

So basically i have a service which takes some ID (Number) as input and gives the details of that specific ID. The given details of the output parent infotable are:

number
deeplink
relatedIssues
owner
createdDate
daysOpen
targetCloseDate

 

So this "relatedIssues" property is another infotable which has another infotable as a property called "fieldData"

and i want to pick the property "CreatedOn" of the fieldData infotable and compare it with the "createdDate" property of the parent infotable. And parse it to have the difference as an output of the service alongside to display it later. 

 

 

10 REPLIES 10

It is quite hard to follow this description, also there is no clear question - what do you want to know?

If you have nested infotables, each of them can have multiple rows, so you will have to iterate through all rows of the nested infotables to make the comparison with the parent table.

Yes the thing you have mentioned, iterating through the rows of nested infotables to access a property in the child infotable.

it would go something like this, but it's still pretty much guesswork

parentInfoTable.rows.toArray().forEach(row=>{
	let relIssues=row.relatedIssues;
	relIssues.rows.toArray().forEach(issuesRow=>{
		let fData=issuesRow.fieldData;
		fData.rows.toArray().forEach(fdataRow=> {
			let difference=row.createdDate-fdataRow.CreatedOn;
			// do something with the difference
		});
	});
});

This does not include the necessary error-checking you would need for robust code and assumes all nested infotables have multiple rows.

Thanks for the reply this is the code, i have logged the value here :

 

 

data.rows.toArray().forEach(row=>{
    let relIssues = row.relatedIssues;
      relIssues.rows.toArray().forEach( issueRow =>{
        let fData = issueRow.fieldData;
          fData.rows.toArray().forEach(fdataRow=>{           
   let valueOne = new Date(row.createdDate); //value in parent table
            let valueTwo = new Date(fdataRow.CreatedOn);// value in child table
            let difference = valueOne - valueTwo;
            logger.warn("value is "+difference);
          });
    }
    )
  }
  )
 
output is  = value is NaN

 Also the value of is  row.createdDate = Thu Feb 08 2024 10:00:33 GMT-0000 (UTC), and fdataRow.CreatedOn =undefined, i think there is some problem the way i am parsing the value.

This means one of the values is not a Date. You should log valueOne and valueTwo then you see which one. Maybe your date string include spaces or have  a format that can't be parsed. Also note that row.createdDate is missing the "T".

Check here which date format is supported: https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-date-time-string-format

i logged the values and got this as a response 

            let valueOne = row.createdDate;
            let valueTwo =fdataRow.CreatedOn;
            let difference = valueOne - valueTwo;
            logger.warn("valueOne "+valueOne);  // valueOne Thu Feb 08 2024 10:00:33 GMT-0000 
            logger.warn("valueTwo "+valueTwo);   // valueTwo undefined
            logger.warn("value difference "+difference);

Yeah so now you removed the "new Date" part, but as you can see, CreatedOn is empty in your infotable, so you can't make that subtraction. You need to decide how you want to handle that case.

I checked in on the values and i was able to get the value and i am getting the final output what i required as well, this is the final code for it:

var data = Things.QueryRequest({
  provider: "WindchillConnector",
  exactNumberSearch: true,
  problemNumber: actionRequestNumber,
  includeAttachments: true,
  localized: true,
});
data.rows.toArray().forEach(row=>{
    let relIssues = row.relatedIssues;
      relIssues.rows.toArray().forEach( issueRow =>{
          let fData = issueRow.fieldData;
          fData.rows.toArray().forEach(fdataRow=>{
             let valueTwo;
            if (fdataRow.name == "CreatedOn") {          
              valueTwo = fdataRow.value;
              let currentDate = new Date();
              let value2Date = new Date(valueTwo);
              let differenceMs = currentDate - value2Date;
              let timeDifference = Math.round(differenceMs / (1000 * 60 * 60 * 24));
              }          
          });
    })
  })
let localInfoTable = data;
let newField = {
    name: timeDifference,
    baseType: 'Number'
};
localInfoTable.AddField(newField);
.
 
So here for example the timeDifference here i got was 20, so i wanted to add this Time Difference as a field in my existing infotable so that i can display it as a label in my mashup but when i use the infotable- "add field" snippet i am getting some error or maybe i am not using it correctly.
 
 

"timeDifference" would be the string argument not a variable so you'd have to put that in quotes: 'timeDifference'

For BaseType I would use the proper spelling, always in capitals, so 'NUMBER'

 

Also note that

 let localInfoTable = data;

will not create a copy of the table but just another reference to the same infotable.

Sure, will look into this, Thanks a lot again for the help.

 

Announcements


Top Tags