@@ -267,13 +267,9 @@ func (client *DataRecordClient) ApplyDataRecord(ctx context.Context, recordId, e
267
267
if nestedMap , ok := value .(map [string ]interface {}); ok {
268
268
delete (columns , key )
269
269
if len (nestedMap ) > 0 {
270
- tableLogicalName , ok := nestedMap ["table_logical_name" ].(string )
271
- if ! ok {
272
- return nil , fmt .Errorf ("table_logical_name field is missing or not a string" )
273
- }
274
- dataRecordId , ok := nestedMap ["data_record_id" ].(string )
275
- if ! ok {
276
- return nil , fmt .Errorf ("data_record_id field is missing or not a string" )
270
+ tableLogicalName , dataRecordId , err := getTableLogicalNameAndDataRecordIdFromMap (nestedMap )
271
+ if err != nil {
272
+ return nil , err
277
273
}
278
274
279
275
entityDefinition , err := getEntityDefinition (ctx , client , environmentUrl , tableLogicalName )
@@ -362,13 +358,9 @@ func (client *DataRecordClient) ApplyDataRecord(ctx context.Context, recordId, e
362
358
for _ , nestedItem := range nestedMapList {
363
359
nestedMap := nestedItem .(map [string ]interface {})
364
360
365
- tableLogicalName , ok := nestedMap ["table_logical_name" ].(string )
366
- if ! ok {
367
- return nil , fmt .Errorf ("table_logical_name field is missing or not a string" )
368
- }
369
- dataRecordId , ok := nestedMap ["data_record_id" ].(string )
370
- if ! ok {
371
- return nil , fmt .Errorf ("data_record_id field is missing or not a string" )
361
+ tableLogicalName , dataRecordId , err := getTableLogicalNameAndDataRecordIdFromMap (nestedMap )
362
+ if err != nil {
363
+ return nil , err
372
364
}
373
365
374
366
relationEntityDefinition , err := getEntityDefinition (ctx , client , environmentUrl , tableLogicalName )
@@ -395,13 +387,9 @@ func (client *DataRecordClient) ApplyDataRecord(ctx context.Context, recordId, e
395
387
for _ , nestedItem := range nestedMapList {
396
388
nestedMap := nestedItem .(map [string ]interface {})
397
389
398
- tableLogicalName , ok := nestedMap ["table_logical_name" ].(string )
399
- if ! ok {
400
- return nil , fmt .Errorf ("table_logical_name field is missing or not a string" )
401
- }
402
- dataRecordId , ok := nestedMap ["data_record_id" ].(string )
403
- if ! ok {
404
- return nil , fmt .Errorf ("data_record_id field is missing or not a string" )
390
+ tableLogicalName , dataRecordId , err := getTableLogicalNameAndDataRecordIdFromMap (nestedMap )
391
+ if err != nil {
392
+ return nil , err
405
393
}
406
394
407
395
entityDefinition , err := getEntityDefinition (ctx , client , environmentUrl , tableLogicalName )
@@ -486,3 +474,15 @@ func parseLocationHeader(response *api.ApiHttpResponse, environmentUrl string, e
486
474
locationHeader = strings .TrimSuffix (locationHeader , ")" )
487
475
return locationHeader
488
476
}
477
+
478
+ func getTableLogicalNameAndDataRecordIdFromMap (nestedMap map [string ]interface {}) (string , string , error ) {
479
+ tableLogicalName , ok := nestedMap ["table_logical_name" ].(string )
480
+ if ! ok {
481
+ return "" , "" , fmt .Errorf ("table_logical_name field is missing or not a string" )
482
+ }
483
+ dataRecordId , ok := nestedMap ["data_record_id" ].(string )
484
+ if ! ok {
485
+ return "" , "" , fmt .Errorf ("data_record_id field is missing or not a string" )
486
+ }
487
+ return tableLogicalName , dataRecordId , nil
488
+ }
0 commit comments