scarse information on passing parameter to a secondary datasource (set up as web service) - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

scarse information on passing parameter to a secondary datasource (set up as web service)

Last post 03-06-2008 01:43 PM by Greg Collins. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-02-2008 04:13 PM

    scarse information on passing parameter to a secondary datasource (set up as web service)

    Hi,

     

    past midnight again so it time to stop googling and ask the experts.

    there is very scarse information to be found on how to pass a parameter to a secondary webservice - that is set up as a webservice- so i cant get my head around the correct syntax

     

    here s the story

    a) my other secondary webservices work fine and pull data across and fill my tables.

    I want to then secondary check the tables and recheck the ones that have a "n.a." value and thus check on a different database if they might have some information

    to do that, i put the (F_firstname)+ (F_lastname) in a variable StrName (this all works fine, no worries here) and want to pass this to my secondary datasource ("list_machines")

     

    if (machina == "n.a.")

    {

    var Strname = nodes(i).selectSingleNode("my:F_Firstname").text+"."+nodes(i).selectSingleNode("my:F_Lastname").text;

    XDocument.UI.Alert(Strname);

    var webs=XDocument.DataObjects["list_machines"].DOM ;

    webs.setProperty("SelectionNamespaces",'xmlns:tns="http://Office2003/Oracle" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');

    webs.selectSingleNode("/dfs:myFields/dfs:queryFields/tns:Landesk_list/StrUser").text=Strname;

    webs.Query(); 

     

     it fails miserably on setting the StrUser parameter as well as to run the query again..(when i skip the parameter and take the default one set during  setup of the wbeservice)

    Any one out there knows what to do to fix this?

     

    tnxs

     

     

     


     

    KriZ
  • 03-03-2008 10:59 AM In reply to

    Re: scarse information on passing parameter to a secondary datasource (set up as web service)

    webs.selectSingleNode("/dfs:myFields/dfs:queryFields/tns:Landesk_list/StrUser").text=Strname;
    webs.Query(); 

     

    Make sure that you are getting a valid node back before trying to set the node value. It could be that there is something wrong with the XPath or some other issue with the selection that is causing a null value to be returned. And you cannot do (null object).text=Strname... that just won't work.

    If you need to do a quick test to make sure it's working at all. Add the StrUser field to a view along with a button that requeries that web service. Then you can type in a value and click the button to make sure that it is at least working right.

  • 03-03-2008 02:54 PM In reply to

    Re: scarse information on passing parameter to a secondary datasource (set up as web service)

    var nodes=XDocument.DOM.selectNodes("/my:myFields/my:R_group/my:RT_directreports") //feth all records for (var i=0; itnxs for the tips Greg.

    after a long and tedious trial and error, i worked it out.

    2 errors i made

    a) webs.selectSingleNode("/dfs:myFields/dfs:queryFields/tns:Landesk_list/tns:StrUser").text=Strname  was the correct one, i was missing a 'tns'. I exported the infopath form locally and looked into the forms for the service setup to get that info.

    b) I needed to query the Adapter, not the DOM.

     

    I recreated the webservice onto a different virtual directory to cut out the Oracle namespace i was carrying along on my webservices. It was pointing to a SQL server anyway. so the namespace changed to ns2 instead of tns

    In case it helps anyway struggeling. here's the code i used

    --------------------------------------------------------------------------

    var nodes=XDocument.DOM.selectNodes("/my:myFields/my:R_group/my:RT_directreports")    //fetch all records  from the repeating table in infopath

    for (var i=0; i<nodes.length;i++)   //and start looping

    {

    var machina = nodes(i).selectSingleNode("my:F_Currentmach").text;      

    if (machina == "n.a.")

    {

     var Strname = nodes(i).selectSingleNode("my:F_Firstname").text+"."+nodes(i).selectSingleNode("my:F_Lastname").text;    // i want to hunt for machines logged on by "firstname.lastname"

     var websobj=XDocument.DataObjects["list_machines"] ;     //list_machines is the name of my secondary data service

    websDOM=websobj.DOM

    websDOM.setProperty("SelectionNamespaces",'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:ns2="http://tempuri.org/"');

    var oUser=websDOM.selectSingleNode("/dfs:myFields/dfs:queryFields/ns2:Landesk_list/ns2:StrUser");     //this is my input parameter

    oUser.text=Strname

    var Adapter= XDocument.DataObjects["list_machines"].QueryAdapter;

    Adapter.Query();     //fire off the query to the webservice

    XDocument.GetDOM("list_machines").setProperty("SelectionNamespaces",'xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:ns2="http://tempuri.org/"');

      var nodes2=XDocument.GetDOM("list_machines").selectNodes("/dfs:myFields/dfs:dataFields/ns2:Landesk_listResponse/ns2:Landesk_listResult/NewDataSet/Table");   //read all nodes returned by the webservice

    var allmachines=""

    for (var j=0; j<nodes2.length;j++)

    {

    var machines=nodes2(j).selectSingleNode("Make").text+" "+nodes2(j).selectSingleNode("model").text

    allmachines=allmachines +" "+machines

    }

    nodes(i).selectSingleNode("my:F_Currentmach").text=allmachines

     }

    }

     In case you're wondering what i was trying to do..

    step A is to fetch machineinfo for a selected user from a secondary webservice.

    step B is to attempt to locate machine for those who're not recorded by lookign to the the log in info on a differnt server (the 'no data available')

    based on machine, the age is set and based on that age, one or more checkboxes get hidden (no upgrade possible)

     

    tnxs for your willingness to help Greg

     

    Gee, i start to like the coding now..

    K

    KriZ
  • 03-04-2008 09:26 AM In reply to

    Re: scarse information on passing parameter to a secondary datasource (set up as web service)

    Glad that you got it figured out and working! It starts to get fun once it all comes together. Not that you won't have challenging tasks and big struggles, but it's still fun!

  • 03-05-2008 02:56 PM In reply to

    Re: scarse information on passing parameter to a secondary datasource (set up as web service)

     Evening Greg,  maybe you know how to query for the following..

     selection box hidden

    From the screenshot in the thread above, you can see that sometimes the checkbox is not there, depending on the age of the hardware in that list.

     

    I set this up with a section where i've placed the check box in. And with the conditional formatting, i worked it out to hide or show the Section and thus the incorporated checkbox. (if 'current machine is X then hide etc..)

     

    My Q:  can you programmatoricaly check for the 'visibility' of this "Section"?  is this an attribute that you can query upon?  Mine are called Section2 and Section3  - very distinguishable.. Ooo

     

    The fun is still around 

    tnxs

     

    KriZ
  • 03-06-2008 01:43 PM In reply to

    Re: scarse information on passing parameter to a secondary datasource (set up as web service)

    You cannot programmatically get at anything in the view... however, since the section uses conditional formatting, there is some formula it is using to decide whether it is hidden. You can use this same formula in your code to decide whether the section is hidden. Make sense?

    If the formula is too complex, then you might be able to add another node somewhere that calculates its value based on the formula (i.e. a Boolean true/false or 1/0). Then the conditional formatting simply looks at the value of this addtional fields, and the code can do the same.

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