Error clarification required:

ErrorCould not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!forEach [line 40]: Error in a!forEach() expression during iteration 1: Expression evaluation error at function a!textField [line 46]: Invalid index: Cannot index property 'SourceDisplayName' of type Text into type Text

Please explain what this means? It seems ambiguous, as it is unable to map a Text type to Text.

Trying to retrieve records from DB with a Query Rule and with foreach trying to display in Editable Grid. The Expression Mode SAIL code is below:

 

=load(

local!sources: rule!CoE_RetrieveAllSources_QueryRule(),
a!formLayout(
label: "Add/Edit Sources of Technologies",
contents: {
a!gridLayout(
totalCount: count(local!sources),
headerCells: {
a!gridLayoutHeaderCell(label: "Display Name" ),
a!gridLayoutHeaderCell(label: "Full Name" ),
a!gridLayoutHeaderCell(label: "Description" ),
/* For the "Remove" column */
a!gridLayoutHeaderCell(label: "" )
},
/* Only needed when some columns need to be narrow */
columnConfigs: {
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:3 ),
a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight:5 ),
a!gridLayoutColumnConfig(width: "ICON")
},
/*
* a!forEach() will take local!employee data and used that data to loop through an
* expression that creates each row.
*
* When modifying the recipe to work with your data, you only need to change:
* 1.) the number of fields in each row
* 2.) the types of fields for each column (i.e. a!textField() for text data elements)
* 3.) the fv!item elements. For example fv!item.firstName would change to fv!item.yourdata
*/
rows: a!forEach(
items: local!sources,
expression: a!gridRowLayout(
contents: {
/* For the Last Name Column*/
a!textField(
label: "Display Name " & fv!index,
value: fv!item.SourceDisplayName,
saveInto: fv!item.SourceDisplayName,
required:true
),
/* For the Department Column*/
a!textField(
label: "Full Name " & fv!index,
value: fv!item.SourceFullName,
saveInto: fv!item.SourceFullName,
required:true
),
/* For the Title Column*/
a!textField(
label: "Description " & fv!index,
value: fv!item.SourceDescription,
saveInto: fv!item.SourceDescription,
required:true
),
/* For the Removal Column*/
a!imageField(
label: "Remove " & fv!index,
images: a!documentImage(
document: a!iconIndicator("REMOVE"),
altText: "Remove source",
caption: "Remove " & fv!item.SourceDisplayName,
link: a!dynamicLink(
value: fv!index,
saveInto: {
a!save(local!sources, remove(local!sources, save!value))
}
)
),
size: "ICON"
)
},
id: fv!index
)
),
addRowlink: a!dynamicLink(
label: "Add Source",
/*
* For your use case, set the value to a blank instance of your CDT using
* the type constructor, e.g. type!Employee(). Only specify the field
* if you want to give it a default value e.g. startDate: today()+1.
*/
value: {
startDate: today() + 1
},
saveInto: {
a!save(local!sources, append(local!sources, save!value))
}
)
)
},
buttons: a!buttonLayout(
primaryButtons: a!buttonWidgetSubmit(
label: "Submit"
)
)
)
)

  Discussion posts and replies are publicly visible

  • i guess query is returning the list of "SourceDisplayName" can you please confirm the type Query Rule is returning
  • The Query Rule is returning below response collected from a Expression View:

    List of Sources: 2 items
    Sources
    Id: 1
    SourceDisplayName: "Digital Platforms"
    SourceFullName: "Digital Platforms"
    SourceDescription: "Digital Platforms refers to a web site portfolio."
    Sources
    Id: 2
    SourceDisplayName: "Data Science"
    SourceFullName: "Data Science"
    SourceDescription: "Data Science helps to uncover the hidden business trends in years of business data."

     

    I think the above list needs to be converted to Appian array form {}, to loop through. Not sure if a list like above results in Appian array to loop through, but may be this could be an issue. 

  • 0
    Certified Lead Developer

    Error in a!forEach() expression during iteration 1: Expression evaluation error at function a!textField [line 46]: Invalid index: Cannot index property 'SourceDisplayName' of type Text into type Text

     Above error means that it is trying to index a field from a value which itself is a text type

     Eg:

    with(

    local!sources:"",

    local!sources.SourceDisplayName

    )

    This will return the error  - Expression evaluation error: Invalid index: Cannot index property 'SourceDisplayName' of type Text into type Text

    But we can avoid such errors in the display by changing the code as below:

    local!sources.SourceDisplayName to index(local!sources, "SourceDisplayName", null)

      

    In your case, looks like the value returned by rule!CoE_RetrieveAllSources_QueryRule() is not in the proper format.

    Eg: if the data returned by rule!CoE_RetrieveAllSources_QueryRule() is {""} then you would get the error message 

    load(

    local!sources: {""},

    /*

    Your code 

    */

    )

    Try using index function to extract the field values from a CDT wherever you want to display

    Also, reject such empty strings returned by the rule before passing it to the foreach in your case.

  • 0
    Certified Lead Developer

    Hi  I recommend you, to use index function to avoid this issue as mention below:

    value: fv!item.SourceDisplayName --to--> index(value: fv!item, "SourceDisplayName", {})

    This behavior is expected when you use (.) to get the nesting value and the value is null, e.g. local!datasubset.data.empName when local!datasubset.data is empty/ local!datasubset.data doesnt contains the value for "empName" attribute

    In your case, local!sources might not have the values for SourceDisplayName / SourceDisplayName might be null

    Hence it's always a safe approach to use index() to avoid such type of issues.


    Also, may i know the return type of local!sources? is that a CDT Array/or Dictionary? or is that a List of Variant?

    Because this must be either of type CDT array or dictionary.


    Best way to debug this could be, just loop this item using foreach and create one textfield during each iteration and define the textField label as fv!item this will give you a clear picture about, what is being returned when the loop is being performed.

    Hope this will help you to debug this issue.

  • Hi ,
    Try to use index function instead of dot operator.
  • 0
    Certified Lead Developer

    You should only use .(dot) operator when you are very very sure that no null value is going to come in your data. For all other cases use index() function to retrieve data.