Description:
rule!OE_QueryOneRecordTypeByForeignKey(recordType, fkField, value)
Gets a record based on its foreign key field value
recordType (RecordType): queried record type
fkField (Record Field): foreign key field
value (Number (Integer)): integer value searched
a!localVariables( local!queryData: a!queryRecordType( recordType: ri!recordType, filters: { a!queryFilter( field: ri!fkField, operator: "=", value: ri!value, ), }, pagingInfo: a!pagingInfo(startIndex: 1, batchSize: 1) ).data, if( a!isNotNullOrEmpty(local!queryData), local!queryData[1], null ) )
if it was OE_QueryRecordTypeByForeignKey, then you simply remove the [1] indexing
Discussion posts and replies are publicly visible
There are several reasons. In my experience, there is no catch all expression. E.g. your code example would not work in a UI refresh scenario because you use a local variable without a refresh-always behaviour.
Next, I am a huge fan of expressive expression names and really prefer a XYZ_GetCaseRecordById() over a generic XYZ_GetSomeRecordsWithAnAndlessListOfOptions().
But there are (number of Appian developers) + 1 opinions.
How would you make this refresh-always behavior? Could you please provide me some example?
Unknown said:How would you make this refresh-always behavior? Could you please provide me some example?
Variables declared in a!localVariables() with default settings (i.e. without using "a!refreshVariables()" to set non-default behaviors) will default to "refresh on referenced variable change" of TRUE and other refresh styles set to FALSE. When local variables are used inside an expression rule like this, then that rule is used on an interface, it can lead to some tricky and unintuitive weird behaviors when in some instances, one would expect the value to update, but it doesn't. In this case if a new primary key is passed in, it WOULD update the result, but in some other corner cases it might not.