remove a particular field from a record before persisting

Certified Lead Developer

Which function do we use to remove a particular field from a record before persisting it?

For example:

recordType!sampleRecord1(
id: null,
column1: A,
column2: B,
column3: C,
column4: D,
column5: E,
column6: F,
column7: G,
column8: H,
relationA: recordType!relationA(
id: null,
column1: A1,
column2: B2,
column3: C3
)
)

I want to remove the id field from both sampleRecord1 and relationA before persisting them.

Reason: The downstream database does not handle id: null well, but if the field is missing or field have a value, it works fine.

The output I want to save should be:

recordType!sampleRecord1(
column1: A,
column2: B,
column3: C,
column4: D,
column5: E,
column6: F,
column7: G,
column8: H,
relationA: recordType!relationA(
column1: A1,
column2: B2,
column3: C3
)
)

Which function do we use to achieve this? i want to handle it dynamically rather mapping individual fields and then persisting .

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    a!localVariables(
      local!record: 'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group'(
        'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group.fields.{5c15adde-4421-4df5-8931-02f60cc6d19f}uuid': "123",
        'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group.fields.{65ab7d0e-3d9c-4c69-a926-408ebb9d17ff}groupName': "Group Name",
        'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group.fields.{60e727df-6c85-4455-ac8a-776efc580b51}description': "Group Description"
      ),
      local!type: typeof(local!record),
      local!recordFields: a!keys(local!record),
      /* create key/value array of fields while excluding the one field in question */
      local!fieldMap: a!forEach(
        items: local!recordFields,
        expression: if(
          fv!item = 'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group.fields.{65ab7d0e-3d9c-4c69-a926-408ebb9d17ff}groupName',
          {},
          a!map(
            field: tostring(fv!item),
            value: index(local!record, fv!item, null)
          )
        )
      ),
      /* create a map from key/values */
      local!map: a!update(
        a!map(),
        local!fieldMap.field,
        local!fieldMap.value
      ),
      /* cast map back to original record type */
      cast(local!type, local!map)
    )

Reply
  • 0
    Certified Lead Developer

    a!localVariables(
      local!record: 'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group'(
        'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group.fields.{5c15adde-4421-4df5-8931-02f60cc6d19f}uuid': "123",
        'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group.fields.{65ab7d0e-3d9c-4c69-a926-408ebb9d17ff}groupName': "Group Name",
        'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group.fields.{60e727df-6c85-4455-ac8a-776efc580b51}description': "Group Description"
      ),
      local!type: typeof(local!record),
      local!recordFields: a!keys(local!record),
      /* create key/value array of fields while excluding the one field in question */
      local!fieldMap: a!forEach(
        items: local!recordFields,
        expression: if(
          fv!item = 'recordType!{b1270365-d71b-4248-aeca-c7f05f03e9da}BLOG_Group.fields.{65ab7d0e-3d9c-4c69-a926-408ebb9d17ff}groupName',
          {},
          a!map(
            field: tostring(fv!item),
            value: index(local!record, fv!item, null)
          )
        )
      ),
      /* create a map from key/values */
      local!map: a!update(
        a!map(),
        local!fieldMap.field,
        local!fieldMap.value
      ),
      /* cast map back to original record type */
      cast(local!type, local!map)
    )

Children
No Data