Skip to main content
January 31, 2024
Question

How to update a recordType records with updateDictionary/update functions?

  • January 31, 2024
  • 9 replies
  • 0 views

Hi,

I've already used the updatedictionary and update functions with CDT, but how it works with RecordType? Could you show me the correct syntax please ?

/* works fine with CDT */
  local!dataVehicles: a!queryEntity(...),

  local!vehicles: a!forEach(
    items: local!dataVehicles,
    expression: a!update(
      data: fv!item, 
      index: {
        "id",
        "model"
      }, 
      value: {
        1,
        fv!item.model
      }
    )
  )
  
/* does not work */
  local!dataVeh: a!queryRecordType(
    recordType: 'recordType!Vehicles',
    fields: {
      'Vehicles.fields.id',
      'Vehicles.fields.model'
    },
    pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 500)
  ).data,

  local!vehicles: a!forEach(
    items: local!dataVeh,
    expression: a!update(
      data: fv!item['recordType!Vehicle'], 
      index: {
        'recordType!Vehicle.fields.id',
        'recordType!Vehicle.fields.model'
      }, 
      value: { 
        1,
        fv!item.model
      }
    )
  )
  
/* Does not work */
  local!vehicles: a!forEach(
    items: local!dataVeh,
    expression: updatedictionary(
      dictionary: fv!item['recordType!Vehicle'], 
      fieldsAndValues: {
        fv!item['recordType!Vehicle.fields.id']: 1,
        fv!item['recordType!Vehicle.fields.model']: "my model"
      }
    )
  )


Best regards

9 replies

January 31, 2024

Hi!

The syntax is fine but calling the record directly doesn't return the data of that record.
You need to query the record type to return the data of the record type.

This could be a possible solution: in items, you can put the function queryRecordType() instead of the record type itself.

local!vehicles: a!forEach(
    items: a!queryRecordType(
        recordType: 'recordType!Vehicle',
        pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 500)
    ).data,
    expression: a!update(
        data: fv!item['recordType!Vehicle'], 
        index: {
            'recordType!Vehicle.fields.id',
            'recordType!Vehicle.fields.model'
        }, 
        value: { 
            1,
            fv!item.model
        }
    )
)

February 1, 2024

Thank you for your reply.
I'm sorry, but yes, I was previously querying my RecordType with "queryRecordType", but I've forgot to add it in my example (I have corrected my example).

So, I confirm I had exactly the same code than you but that does not work. After testing again I still have the same error :

Expression evaluation error at function a!forEach [line 126]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function a!update parameter 1 [line 128]: Vehicles must be indexed by its corresponding record type fields or relationships

harshitb6843
February 1, 2024

As the error message suggests, you are not indexing the vehicle record correctly in the data parameter of your a!update function - docs.appian.com/.../reference-records.html
Try taking a look at it or paste your code here so we can take a look. 

mathieud0001
Brainy
February 1, 2024

Should look something like this

February 1, 2024

thank you

konduruc733182
February 1, 2024

Hello [mention:1bef179229004ddc96b85765d77cfdc1:e9ed411860ed4f2ba0265705b8793d05] 

When you are using a CDT its okay to have strings as a reference. But in case of Records you need to use Record Type references.
Below is an Example from Documentation



Please read this for better understanding.


Update for Records

February 1, 2024

Yes, thank you.
In my initial I was indeed querying my RecordType before, but I've forgot to add it in my example, sorry.
My question is still valid, but concerns an error I met (see above please)

niranjanreddym9323
February 1, 2024

local!vehicles: a!forEach(
    items: local!dataVeh,
    expression: a!update(
      data: fv!item, 
      index: {
        'recordType!Vehicle.fields.id',
        'recordType!Vehicle.fields.model'
      }, 
      value: { 
        1,
        fv!item.model
      }
    )
  )

Hi [mention:1bef179229004ddc96b85765d77cfdc1:e9ed411860ed4f2ba0265705b8793d05] ,

for the second case, you can directly use fv!item instead of indexing record type in data parameter of index function to update the value.


For third case, updateDictionary function will only work for dictionary/cdt types.

February 1, 2024

You're right : fv!item works fine.

Now, the last issue I have is on : fv!item.model,

value: {
  1,
   fv!item.model
}

Appian needs a RecordType notation so I've changed it with : fv!item['recordType!Vehicles.fields.model'] 
and all is fine now :-)

Thanks, a lot