dynamically index record fields

Certified Senior Developer

Hi all,

We are switching to a full record centric approach for our new projects. In our old projects we used to have an expression rule "XXX_setCdtDefault()" this would set the fields createdBy, createdOn, lastmodifiedBy and lastModifiedOn for each CDT right before saving.

if(
  a!isNullOrEmpty(ri!cdt),
  ri!cdt,
  a!update(
    ri!cdt,
    {
      "createdOn",
      "createdBy",
      "modifiedBy",
      "modifiedOn"
    },
    {
      a!defaultValue(ri!cdt.createdOn, now()),
      a!defaultValue(ri!cdt.createdBy, loggedInUser()),
      loggedInUser(),
      now()
    }
  )
)

Since we will now use the Write Records smart service, we are no longer working with CDT's.
Is there a way to do the same thing as before in a generic way for record types. If we want to update a record type, we need to pass the references to the record fields, so we cannot use the generic "createdOn" etc..

I have come up with a workaround as shown below, but I would prefer it if we could just update the record instead of casting it to a map and back to a record type.

if(
  a!isNullOrEmpty(ri!type),
  ri!record,
  cast(
    ri!type,
    rule!ENM_setCdtDefault(    
      cast(
        'type!{http://www.appian.com/ae/types/2009}Map',
        ri!record
      )
    )
  )
)

Thanks!

  Discussion posts and replies are publicly visible