How to cast record field in the format of text (#"urn:appian:record-field:...../.....) to record field?

Certified Lead Developer

Hi ,

when I sort on a record backed read only grid , sort field that is stored is in the format #"urn:appian:record-field:v1:ff132d24-cf88-4234-88ae-9fe224dd3dfd/b05761f7-3e63-4e76-bb2b-10c4886815d8.

I need to store this sorting preference for each user level. This is not being stored in record field type. its type is string. Even if i want to cast it to record field I am getting error that cast invalid.

Only way i could find to covert this into a record field is by using eval() function. But eval() function is a hidden one. Can some one give me an idea on how to handle this?

Thank you

  Discussion posts and replies are publicly visible

Parents
  • The only way I can think of doing this is to have some kind of mapping rule. In that rule you could have a list of key value pairs that have a field name and the field reference, and then just store the field name in the database. Then, use your mapping rule to return the corresponding field as needed. Here's the mapping from text to record field (you likely also need one the other direction to determine what to save in the database):

    It would certainly depend on how dynamic your interface is - like if this could be across dozens of record types the maintenance would be difficult keeping up with all of these fields - but if it's only a single record type this might work!

Reply
  • The only way I can think of doing this is to have some kind of mapping rule. In that rule you could have a list of key value pairs that have a field name and the field reference, and then just store the field name in the database. Then, use your mapping rule to return the corresponding field as needed. Here's the mapping from text to record field (you likely also need one the other direction to determine what to save in the database):

    It would certainly depend on how dynamic your interface is - like if this could be across dozens of record types the maintenance would be difficult keeping up with all of these fields - but if it's only a single record type this might work!

Children
  • 0
    Certified Lead Developer
    in reply to Peter Lewis

    Hi Peter,

    I did already use a rule to map the field alias and record fields as you have shown. 

    It has two functionalities. if i pass text key , it will return corresponding record field. and if i pass record field it will return the text key. It is working fine.

    But the problem here is the how to pass the record field value from parent rule to this rule.

    i have to pass like below.

    /*Here if i am expecting key as output
      so I am passing recordfield and returnKey attributes*/
    
    rule!APP_fetchRecordAttributeByValue(
        key_txt:null,
        value_recordField: ri!paginginfo.sort.field,
        returnKey_bool:true
        )

    in the above code segment, value_recordField parameter, is not evaluating it to a record field ,but to a text field. so it is not returning key i am expecting.

    But below code segment works, with eval function.

    rule!APP_fetchRecordAttributeByValue(
        key_txt:null,
        value_recordField: eval(ri!paginginfo.sort.field),
        returnKey_bool:true
        )

    I know i should not use hidden function , but is there any other way around for this?

  • Ahh yes I see your problem - the problem is actually saving the field result out of the sort info. I agree that I don't see a great result beyond using the UUID of the field as the key in the mapping rule.

  • 0
    Certified Lead Developer
    in reply to Peter Lewis

    Even though there is no solution found for aforementioned Problem with casting. 

    I found the solution for the use case though. Instead of storing the record field, I stored sorting info directly using externalize function in database. used internalize function to convert it back. 

    This way it is retaining the Fields and its type as it is.

    This work for my use case. But Solution for record field casting from text type is still not found.

    /*While storing it into database*/
    externalize(a!pagingInfo(
    1,
    50,
    a!sortInfo(recordType!Request.fields.id,
    false))
    
    /*we can use internalize function back to convert back to original format*/

    Thank you  and  for spending time on this.