Having trouble with a cascading dropdown. Basically, I have an editable grid tha

Certified Senior Developer
Having trouble with a cascading dropdown. Basically, I have an editable grid that has 3 dropdowns. The user selects a user from the first dropdown, assigns a role to the user with the second dropdown and assigns an area of expertise with the third dropdown. I got the rule to work with the first 2 dropdowns, but the choices presented with the third dropdown are dependent on the user selected in the first one. I have a query rule that brings back a list of expertises based on the userId. So I created a local!selectedUserId variable to use in my query rule that displays the dropdown list and added an a!save statement to update that local variable with the selected user id. But I get an error when I access this form because the query rule cannot find a userId. Here's the error I'm getting and I've attached my updated rule for the grid.
Expression evaluation error in rule 'ips_getexpertisebyuserid' (called by rules 'ips_assignuserrolesgr...

ips_assignUserRolesGrid_new.txt

OriginalPostID-170455

OriginalPostID-170455

  Discussion posts and replies are publicly visible

  • @judym As I said earlier, it's not a valid version because I am explicitly saving null value into expertiseId. Because I guess expertiseId is of type integer and local!expertise.data.expertise might evaluate to a string and trying to store string into integer will create a new error. So I have just changed the display and also saving null value into expertiseId explicitly. Please take a keen look below:
    a!dropdownField(
    label: "Area of Expertise",
    choiceLabels: local!expertise.data.expertise,
    choiceValues: local!expertise.data.expertise,
    placeholderLabel: "---Assign Area of Expertise---",
    \ t/*Null handling being done for value attribute*/
    value: if(rule!APN_isEmpty(ri!newTeamLink_cdt[ri!index]),null,if(rule!APN_isBlank(ri!newTeamLink_cdt[ri!index].expertiseId),null,ri!newTeamLink_cdt[ri!index].expertiseId)),
    saveInto: {
    \ ta!save(ri!newTeamLink_cdt[ri!index].expertiseId,null)
    \ t},
    required: true(),
    readOnly: false()
    )

    If you could let me know the data structure of expertise and the definition of rule!ips_getExpertiseByUserId() I could try to help you debug the issue.
  • 0
    Certified Senior Developer
    You are correct with your assumption. expertiseId is of type integer and expertise is of type text. The query rule basically gets all data where 'userId = userId' and sorts by expertise. The actual data type has an id (a/I), userId, expertiseId, and expertise. So userId 4 may have 3 records (areas of expertise) in the table whereas userId 6 may have 2 areas of expertise. All users have at least 1 record in the table. Does that help?
  • @judym Some more information please - May I know the column names exactly and also if rule!ips_getExpertiseByUserId() is a query rule?

    Meanwhile could you please test the following code in an expression rule separately and do let me know the outcome?

    with(
    \ tlocal!expertise: rule!ips_getExpertiseByUserId(),
    \ tlocal!expertise_datasubset: todatasubset(local!expertise),
    \ tindex(local!expertise_datasubset,"id",{})
    \t )
  • 0
    Certified Senior Developer
    Column Names are: expertiseLinkId (int), userId (int), lastName(text), firstName(text), expertiseId (int), expertise(text). rule!ips_getExpertiseByUserId() is a query rule with input being 'userId' and query conditions userId = userId, sort by expertise.
    I'm not sure I tested the code above correctly. I created an expression rule and put
    =with(
    local!expertise: rule!ips_getExpertiseByUserId(ri!userId),
    local!expertise_datasubset: todatasubset(local!expertise),
    index(local!expertise_datasubset,"id",{})
    )
    with one input (userId[int]), assigned a test value of '6' that should bring back results and got {}
    Attached is a screen shot.

  • @judym Got it, very simple. You are trying to use a field which is not present in your data structure.

    So let' see the below line which is of "Area of Expertise" dropdown:
    choiceValues: index(local!expertise.data,"id",{})
    Here we are trying to access a column by name 'id' in the queried data. As it isn't present, you are not able to obtain any values for 'choiceValues' attribute.

    So your actual code should look like this I guess:
    choiceValues: index(local!expertise.data,"expertiseId",{})

    If my assumption is correct, please try the attached file once again and have a keen look at "Area of Expertise" dropdown.
  • 0
    Certified Senior Developer
    That was it! I knew it had to be a simple thing. I'm so used to saving the 'id' that I didn't pick up on that. Thank you SO much!
  • @judym Happens some times with most of us.! Glad to hear that the problem is resolved. :)