Setting the id of a type through a stored calc


I have a stored calc that looks like this

orgField Organization stored calc “exists(a) && exists(b) ? concat(a,b) : null”

where a and b are strings that are defined by what we’ll call the DATA field in the transform.

What I want to do is, if a and b exist, create an Organization whose id is the concat of a and b.

I would perform this logic in the transform, but I don’t know how to check for the existence of DATA in the transform. I don’t want to do a filter in the transform annotation, because the record should be populated even if DATA doesn’t exist.

Is there any way to declare an id for organization directly in the stored calc logic or to do an exists check for DATA in the transform?


I am not sure I am following the use case completely.

  1. You have an inbound canonical file that has a field called DATA.
  2. The field is optional; sometimes it will be null.
  3. If DATA is null, you still want to create a record of your target type. However you don’t want to populate orgField on that record.

Correct? If yes, you can just put the expression that you used for the calc into the transform itself:

orgField: ~ expression "exists(a) && exists(b) ? {id: concat(a,b)} : null"

(my syntax may be off, but hopefully this gives you an idea)


Hey Jonathan,

Do you want to actually create an Organization and persist it to the database? Or just create a reference to an Organization on the Type that you are creating the stored calc field on?

If you don’t want to persist a new Organization, you can create the reference to an instance of an Organization with logic similar to that which you have above (and exactly as Yaroslav suggests), roughly equivalent to the following (some minor syntax may need to be adjusted):

orgField Organization stored calc “exists(a) && exists(b) ? {id: concat(a,b)} : null”

If you want to actually persist a new Organization based on that logic, there are several ways:

Option 1 (probably the best option): if field a and field b that you reference above come in on the same canonical file at the same time, then make a new conditional transform (Canonical transform exist condition annotation) to the Organization Type and you are all set.

If Option 1 is not possible:
Option 2: Create an Analytic on the Type you are working with above (the Type that has fields ‘a’ and ‘b’) and have the logic of that Analytic return an Organization whenever fields ‘a’ and ‘b’ exist. Be aware that this will run automatically, and possibly overwrite existing organizations, which could be good or bad depending on your data/application.

If you want more control over how and when this happens, you can create a BatchJob that does an Organization.make() and then .merge() leveraging the ‘a’ and ‘b’ fields Type you are working with above. This is a bit clunky and manual, but would allow you to merge effectively.

Let us know what exactly you’re trying to accomplish.