Creating Objects in Stored Calc Expression

#1

I have a field that is a reference to a C3 type. Is it possible to create the C3 object in the expression with something like:

refField1: string
refField2: int
fieldName: TypeName stored calc "{id: refField1, property: refField2}"

where TypeName is a different entity type.

There is a workaround, but I just want to ask if it’s possible to do such a thing.

0 Likes

#2

Yes, your expression should pretty much work as you indicated. However TypeName should not be a persistable type in this case.

Do you get any errors?

0 Likes

#3

I just tried it again with TypeName no longer persistable, and it still does not work. No errors; just none of the stored calcs for fieldName are filled when I do TypeName.refreshCalcFields().

0 Likes

#4

Can you provide your actual code example?

0 Likes

#5

All I am changing here are the names of the types and fields.

First type:

type Info {
  name: string
  property: string
}

Second type:

entity type ClassType {
  info: Info stored calc "{nm1: name, prp1: property}"
}
0 Likes

#6

In this example, name, and property would need to be defined as fields on ClassType, and nm1 and prp1 would need to be fields defined on Info

0 Likes

#7

Something like this would work… tbh i don’t see the value of what you’re trying to do, maybe my example makes it clear? In the below example you must have loaded some data into a field ClassType.nm1.It would have been better to just load that data directly into ClassType.info.name directly.

type Info {
  name: string
  property: string
}

entity type ClassType {
  nm1: string
  prp1: string
  info: Info stored calc "{name: nm1, property: prp1}"
}

Alternatively, give ‘ClassType’ the properties of an “Info” directly

type Info {
  name: string
  property: string
}

entity type ClassType mixes Info
0 Likes

#8

Sorry, I accidentally omitted the name and property fields in ClassType. I basically have exactly what is in @rileysiebel’s first example. This is still not populating when I do the ClassType.refreshCalcFields() command.

The reason we’re doing this sanity check is that we were initially trying to do something more complicated (creating an stored calc array of Info objects), but when that wasn’t working, we tried just creating a single Info object, which still doesn’t work.

The original thing we were trying to do is this:

entity type SourceType schema name 'ELMT' {
    sourceProp1: string
    sourceProp2: string
    filterField: int
}

type Info {
    name: string
    prp1: string
    prp2: string
}

entity type ClassType schema name 'CLSTP' {
    fixedSizeArray: [SourceType]
    desiredStoredCalcField: [Info] stored calc "[{name: 'InfoType1', prp1: fixedSizeArray.(filterField == 1).sourceProp1, prp2: fixedSizeArray.(filterField == 2).sourceProp1}, {name: 'InfoType2', prp1: fixedSizeArray.(filterField == 1).sourceProp2, prp2: fixedSizeArray.(filterField == 2).sourceProp2}]"
}
0 Likes