Hi everyone ,
I have scenario where my data is stored in Map/Dictionary.
Now this has to be stored in record.Each field to be mapped with the respective record field.Considering the volume, Is there a way to use the Field Id to map the value.Example:
a!localvariables(
local!list:{{columnName:"Name",recordFieldId"4567898765"},
local!list:{
{
columnName:"Name",
recordFieldId"4567898765"
},
{columnName:"Desc",recordFieldId"4567856894"},/* Now the data to be mapped */a!foreach(locaL!list,index(record,fv!item.recordFieldId,null))
columnName:"Desc",
recordFieldId"4567856894"
},/* Now the data to be mapped */a!foreach(locaL!list,index(record,fv!item.recordFieldId,null))
)
Discussion posts and replies are publicly visible
No, you cannot use Field IDs to dynamically map data to records.
/* Method 1: Direct casting (recommended for volume) */ cast( recordType!YourRecord, local!mapData ) /* Method 2: Using record constructor */ recordType!YourRecord( recordType!YourRecord.fields.name: local!mapData.name, recordType!YourRecord.fields.desc: local!mapData.desc ) /* For Bulk Operation */ a!forEach( items: local!listOfMaps, expression: cast(recordType!YourRecord, fv!item) )
The Field name in the local and the record are different.I dont want to do it manually since it has large set of fields.
And this local has data of the related records too. So here we cant use direct casting.
Can you provide some example of the data structure you have. If your field id in map is analog to record field's field id then index should work. Yet some more details will be better
Have you considered making a dictionary/map mapping the fieldName to the recordField to store the mappings and then using that for the copy? This would allow you to have recordFields using relationships.
When field names differ between source and record, you must manually map each field using recordType!Record.fields.fieldName: sourceData.differentName.Direct casting only works when field names match exactly. Related records require separate handling after parent records are created.
Since it has a big list, trying to find an alternate way.
I have a grid with 30 Columns.All these column names are stored in Table.In the grid, used a!foreach to populate the headers.For rows, a!foreach is used for each row generation. And for each column, again a!foreach is used. So here just with index, the values to be saved in the appropriate field.
In the picture, used an expression rule to return the recordtype!record.field based on the label.
Is there any way, we get the field index from table. Because we already have the Column Labels in table which is queried in the interface. If the field index is stored in table, we can use it easily. Considering the performance of displayvalue() when we have large set of columns, I am checking the possibility of taking it from the table.
Let's give it a try by doing this,Update an Rule MCI_returnRecordFieldBasedOnLabel
a!localVariables( local!fieldMap: { {label: "Name", field: "name"}, {label: "Description", field: "description"}, {label: "Status", field: "status"}, /* Add all 30 field mappings here */ }, index( index( local!fieldMap, wherecontains(ri!label, local!fieldMap.label), {} ), "field", null ) )
a!localVariables( local!columns: rule!getColumnsFromTable(), /* Your column labels from DB */ local!data:{}, /* Your data */ { a!gridLayout( rows: a!forEach( items: local!data, expression: a!gridRowLayout( contents: a!forEach( items: local!columns, expression: a!textField( value: index( fv!item, rule!MCI_returnRecordFieldBasedOnLabel( label: fv!item.columnLabel ), null ), saveInto: { a!save( index( fv!item, rule!MCI_returnRecordFieldBasedOnLabel( label: fv!item.columnLabel ), null ), save!value ) } ) ) ) ) ) } )