Typescript function, ontology action append question

Hello,

I’m using typescript in an action backed by a function to feed in data from an ontology object (excludeaaas below, , reading in as an array of items) and I’d like to append new rows to an object called YYYExclusions (below) .

I’m looping through each ‘item’ in excludeaaas, doing a bit of transformation and adding the the new columns. Not sure if what I’m doing below will truly appending to the dataset or will I be overwriting rows? any help with typescript would be great!!

@OntologyEditFunction()
public async myOutput(
YYYExclusions: YYYExclusions,
excludeaaas: Masterdata[ ],
expirationDate: LocalDate,
submittedBy: string,
submitDate: LocalDate
): Promise {

excludeaaas.forEach(aaaexcluded => {
    const ExpirationID = `${aaaexcluded.Id}_${expirationDate}`;
    const expirationDatestr = expirationDate.toString();
    const currentDatestr = submitDate.toString();
    YYYExclusions.ExpirationID = ExpirationID
    YYYExclusions.aaaCategory = aaaexcluded.aaaName
    YYYExclusions.Id = aaaexcluded.Id
    YYYExclusions.expirationDate = expirationDate
    YYYExclusions.submittedBy = submittedBy
    YYYExclusions.submittedat = submitDate


});

}

Hey @pens2,

If you want to create new instances of YYYExclusion you need to use Objects.create()... syntax. Though I’m not exactly sure if creating new objects is what you mean by appending to do the dataset. Does that help or if not, please could you provide a bit more explanation as to what you’re trying to achieve?

Hi @jedboffey correct. YYYExclusions is an object without a backing data source. The object currently contains the following 6 columns and 2 rows in each column: ExpirationID: 123, 456; aaaCategory ‘test1’, ‘test2’; Id: 1, 2; expirationDate: 8/6/2025, 8/9/2025; submittedBy: ‘Josh’, ‘David’; submittedat : 8/4/2025, 8/2/2025

Going forward, I do not want to create a new instance of the object, I only want to add/append new rows, and not over-write any records already in this object.

I wrote the following below, thoughts?

@OntologyEditFunction()
public async myOutput(
YYYExclusions: YYYExclusions,
excludeaaas: Masterdata,
expirationDate: LocalDate,
submittedBy: string,
submitDate: Timestamp
): Promise {
excludeaaas.forEach(aaaexcluded => {
const ExpirationIDcat = ${aaaexcluded.Id}_${expirationDate};
const writebbbb = Objects.create().YYYExclusions(ExpirationIDcat);
writebbbb.category = aaaexcluded.categoryName;
writebbbb.expirationDate = expirationDate;
writebbbb.Id = aaaexcluded.Id;
writebbbb.submittedAt = submitDate;
writebbbb.submittedBy = submittedBy;
})
}

Objects.create() is the way to go, got it to work, thx!!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.