Using infopath formula with filters and returning multiple results - InfoPath Dev
in

InfoPath Dev

Using infopath formula with filters and returning multiple results

Last post 11-24-2008 08:27 AM by h.elshabini. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 11-24-2008 03:29 AM

    Using infopath formula with filters and returning multiple results

    Hello, this is my first post i will try to be as brief and clear as i can, i am using infopath 2007 to create an infopath document to simulate some kind of a workflow.

    well anyways, i have a secondary datasource xml file called UserRoles.xml and this file contains the user names of my company and the roles they are allowed to choose from at some point during the document workflow based on other criteria of coarse.

     the datasource is like this:

    <?xml version="1.0" encoding="utf-8"?>
    <roles>
        <role>
            <name>Account Manager</name>
            <users>
                <username>user1</username>
                <username>user2</username>
                <username>user3</username>
            </users>
        </role>
        <role>
            <name>Proposal Manager</name>
            <users>
                <username>user8</username>
                <username>user1</username>
                <username>user3</username>
                <username>user7</username>
                <username>user9</username>
            </users>
        </role>
        <role>
            <name>Department Head</name>
            <users>
                <username>user4</username>
                <username>user5</username>
                <username>user2</username>
            </users>
        </role>
    </roles>

     

    now as u can see, each single user might be a member of multiple roles, which is required in my workflow because at some point the user can do things based on his role as account manager then do something else based on his role as proposal manager.

     the problem is that how do i retreive which roles is this specific user assigned to?

    i get the user using the userName() function

    i create a repeating field called "fldAllowedUserRoles"

    and i make it's default value like this: name[username = userName()]

    the problem is that this formula returns only the first occurance of this specific filter and exits, without checking if this case exists again further in the document.

    now how do i create a folrmula to return all the results for this specific username?

  • 11-24-2008 03:50 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    Hello and welcome to the forums,

    If you use this value in a text box then it will give the first result only.

    So use this filter in a drop down field to get all the occurrences of that specific filter.

    Swathip
    www.ggktech.com
  • 11-24-2008 04:06 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    yes i know, but i need to retrieve these values in code, so they must be written to the main datasource. which i don't think they exist in there if i just populate the drop down with the values, or do they?

  • 11-24-2008 05:47 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    Hi,

    How you are getting the values in the code. I think you are using selectSingleNode("xpath") method. Instead use selectNodes("xpath"). So that you will get all the filtered values. Set these values to a repeating field in main data source and in the drop down properties select ‘look up values in the form's source' and select the repeating field in the Entries box.

    You can achieve this functionality without code by using the below steps.

    1. Go to Drop down box properties.

    2. Select Look up values from an external data source.

    3. In the data source drop down, select the secondary connection.

    4. Select the role. Click Filter Data.

    5. Select username is equal to userName().

    6. Click ok to close all the windows.

    7. Make sure that name is selected in the value and Displaye Name fields.

    Finally the expression in the entries box should be like ‘/roles/role[users/username = xdUser:get-UserName()]'

     

    Swathip
    www.ggktech.com
  • 11-24-2008 06:37 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    Thank you for your reply, 

    but the steps you mentioned just populates the data in a drop down list, which is not helping me because the interface is totally isolated from the data in infopath,

    let's say i have a data field in the main datasource = field1

    i need field1 to contain the values of all the roles in which this current user can be assigned. not the values chosen from the drop down, no....but i want for example to create a rule in the form rules, to fill field1 with all the values of this user's roles.

    i mean i cannot actually make a drop down, and make the user choose from it his role, it has to be done automatically depending on other criteria.

    well anyways i tried to make that field1 repeating and tried another bunch of stuff....didn't work either...always returns the first value it meets and thats it....

    however i made a workaround for now for my scenario, is that i wrote this "other criteria" i was talking about in the xml document right next to the username, and filtered using multiple values...

    but if anyone can plaese solve this for me, i'd be so gratfull

  • 11-24-2008 06:56 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    Hello and welcome to our forums!

    This tutorial might help you. http://www.infopathdev.com/blogs/matt/archive/2006/04/18/Automatically-Populate-Fields-from-a-Drop_2D00_Down-Selection.aspx. It uses text boxes to populate from xml.

     

    Jo-Anne Alfafara
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 11-24-2008 07:03 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    I don't believe the default value on a field can populate a repeating field like that, and this doesn't sound like something that can be done with rules either.  It wouldn't be too difficult to do with code, but are you comfortable with code?

     But may I first ask what you plan to do with the field once it is copied over?  Depending on that answer you may be able to use the data in-place without copying it first.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-24-2008 07:23 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    yes i am familiar with code, c# especially, but this whole XPath mess just pisses me off and i did not want to get messy untill im sure that there is no way to do that out of the box.

    anyway, about this field, i play to keep the role names which the current user can play in this document, and depending on it user may or maynot have restrictions in the form.

    like im gonna use it for conditional formatting and things like that, to acheive some security restrictions.

     the only problem is that a user might have multiple roles, this is where the problem emerged. so i need to have the roles that he can play check them if they contain or not a certain string every now and then.

     

    any help?

  • 11-24-2008 07:45 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    XPath can be very useful, and not too confusing once you get the hang of it.

     Anyway, if you want to hide a section when a user is not in a certain role, you should be able to use XPath like the following in the conditional formatting dialog:

    not(xdXDocument:GetDOM("roles")/roles/role[name = "Account Manager"]/users/username[. = userName()])

    You would replace the "roles" in quotation marks with the name of the secondary data source, and "Account Manager" with the appropriate role name.  You can use AND and OR, or remove the enclosing not() to create more complex logic.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-24-2008 08:27 AM In reply to

    Re: Using infopath formula with filters and returning multiple results

    thnx jimmy, i tried what u told me and it worked however i cannot do this to every single section in the form, its pretty big.

    well i did a work around by putting in the xml document (datasource) enough info inorder for it to return to me the most appropriate user role after a ton of filtering :S and then im gonna do actions for this user depending on this only role i got back from the xml document.

    well thnx for helping me but it seems there is no way to simply populate a field with multiple values automatically, unless it's in the interface...thnx alot...

Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.