select parent based on child value

6 views
Skip to first unread message

Mani

unread,
Jun 3, 2020, 5:13:13 AM6/3/20
to Orbeon Forms
Hi Alex - I'm storing this xml as a dataset using an action and pre-populate some employee details. 

<json type="object">
    <staff type="object">
       <lastName>Manish</lastName>
       <firstName>CCC</firstName>
       <departmentPositions type="array">
            <_ type="object">
                <departmentId>101111</departmentId>
                <departmentName>North East</departmentName>
                <positions type="array">
                    <_ type="object">
                        <positionTitle>Teacher</positionTitle> 
                    </_>
                 </positions>
              </_>
                  <_ type="object">
                <departmentId>101112</departmentId>
                <departmentName>South East</departmentName>
                <positions type="array">  
                    <_ type="object">        
                        <positionTitle>Principal</positionTitle>                      
                    </_>
                </positions>
            </_>
        </departmentPositions>
    </staff>
</json>

While filling the form, user selects one of the multiple positions he has got from a positions dropdown. On selection of the position(control-employee-position) I should autofill the associated departmentName in another text control

for which I'm using the following xpath as calculated value - xxf:instance('fr-dataset-staffDetails')/staff/departmentPositions/_/departmentName[positions/_/positionTitle = xxf:instance('fr-form-instance')//control-employee-position]

I do not get the desired result. May I know what am I doing wrong here?


Alessandro Vernet

unread,
Jun 3, 2020, 6:28:21 PM6/3/20
to orb...@googlegroups.com
I notice at least 1 typo in that expression: `positions` isn't inside
`departmentName`, but inside the parent `_`. So something like this seems
"more correct":

xxf:instance('fr-dataset-staffDetails')/staff/departmentPositions/_[positions/_/positionTitle
=
xxf:instance('fr-form-instance')//control-employee-position]/departmentName

If this doesn't do it, one way to debug this is by just keeping a part of
the expression, and adding a `count(…)`, to check that at every level it
returns something (i.e. if it returns 0, you know that the expression you
have didn't return anything).

I hope this helps,

‑Alex

-----
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
--
Sent from: http://discuss.orbeon.com/

Alessandro Vernet

unread,
Jun 23, 2020, 4:06:11 PM6/23/20
to orb...@googlegroups.com
Hi Manish,

Did you manage to make that expression work? (Also, I am noticing that the
XPath in my previous message got mangled, so let me know if you're still
working on this!)
Reply all
Reply to author
Forward
0 new messages