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
I do not know of a way to "remove" a already populated field from a record.
I tried to cast it to a map, set the ID to null, and cast it back to the record, but this did not help.
There are no such functions to remove the field having null value from a record. However we can create an expression to check for null values and remap the record after removing null id fields from the record. There are considerations, of course, like what all fields need to be handled when their value is null depending on downstream system requirements. Below is a sample expression that checks for null id columns as per your description. Hope this gives a general idea.
For better understanding, I have formatted record types so that unnecessary uuids don't take space! Replace the record references with appropriate formatting.
a!localVariables( local!data: recordType!Case Main( recordType!Case Main.id: null, recordType!Case Main.name: "A", recordType!Case Main.submitter: "B", recordType!Case Main.relationships.DocRelation: { recordType!Case Document( recordType!Case Document.id: null, recordType!Case Document.size: 12 ) } ), local!NullIdRemovedChildData: a!forEach( local!data[recordType!Case Main.relationships.DocRelation], if( a!isNullOrEmpty( fv!item[recordType!Case Document.id] ), { recordType!Case Document( recordType!Case Document.size: local!data[recordType!Case Document.size] ) }, fv!item ) ), local!NullIdRemovedData: if( a!isNullOrEmpty( local!data[recordType!Case Main.id] ), recordType!Case Main( recordType!Case Main.name: local!data[recordType!Case Main.name], recordType!Case Main.submitter: local!data[recordType!Case Main.submitter], recordType!Case Main.relationships.DocRelation: local!NullIdRemovedChildData ), local!data ), local!NullIdRemovedData )
The below code might help you. It gives you the fields which are having only non null values
a!localVariables( local!record: 'recordType!{b1ea8073-bc4b-4054-b4bb-9a8dfc3ce0d5}WTA Developer Details'( 'recordType!{b1ea8073-bc4b-4054-b4bb-9a8dfc3ce0d5}WTA Developer Details.fields.{190df1d5-68fc-404f-8f5a-a520aa180a6e}id': null, 'recordType!{b1ea8073-bc4b-4054-b4bb-9a8dfc3ce0d5}WTA Developer Details.fields.{17f5b725-96de-4ba4-850a-a4890c5b0a14}developerDesignation': "Lead", 'recordType!{b1ea8073-bc4b-4054-b4bb-9a8dfc3ce0d5}WTA Developer Details.fields.{e236bd92-5be6-4638-a80c-2ffeeb87962f}isActive': true() ), reject( fn!isnull, a!foreach( a!keys(local!record), if( a!isNullOrEmpty(local!record[fv!item]), "", fv!item ) ) ) )
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) )
That gives the field names / field references, of course, but it doesn't return an instance of the record type with the desired field removed, which was the ask...
Yeah My bad. The below code should solve the issue. i changed the logic to find null values and remove them from the original record.
a!localVariables( local!record: 'recordType!{b1ea8073-bc4b-4054-b4bb-9a8dfc3ce0d5}WTA Developer Details'( 'recordType!{b1ea8073-bc4b-4054-b4bb-9a8dfc3ce0d5}WTA Developer Details.fields.{190df1d5-68fc-404f-8f5a-a520aa180a6e}id': null, 'recordType!{b1ea8073-bc4b-4054-b4bb-9a8dfc3ce0d5}WTA Developer Details.fields.{17f5b725-96de-4ba4-850a-a4890c5b0a14}developerDesignation': "Lead", 'recordType!{b1ea8073-bc4b-4054-b4bb-9a8dfc3ce0d5}WTA Developer Details.fields.{e236bd92-5be6-4638-a80c-2ffeeb87962f}isActive': true() ), local!nullfields: reject( fn!isnull, a!forEach( a!keys(local!record), if( a!isNullOrEmpty(local!record[fv!item]), fv!item, "" ) ) ), remove(local!record, local!nullfields) )