add values to repeating table of a WS with JScript, infopath 2003 - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

add values to repeating table of a WS with JScript, infopath 2003

Last post 12-17-2008 05:38 AM by Ulk31. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 12-16-2008 08:39 AM

    • Ulk31
    • Not Ranked
    • Joined on 12-16-2008
    • Posts 4

    add values to repeating table of a WS with JScript, infopath 2003

    Hi,

    I'm albe to insert an new line with

     XDocument.View.ExecuteAction("xCollection::insert", "tbl_UserRow_11");

    but how can I add values to the fields of the new line?

    My primary datasource (implemented as a webservice) looks like this:

    - myFields
      - dataFields
        - tns:getInstanceResponse
          - getInstanceResult
            - :workitem
                CurrentUserId
                CurrentUserName
              - tbl_User
                - tbl_UserRow
                    tbl_UserType
                    tbl_UserComment
                    tbl_UserName

    I seached a lot in this forum, but nothing help.

    can anybody help?
                  
    Regards Ulk

     

  • 12-16-2008 08:57 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: add values to repeating table of a WS with JScript, infopath 2003

    Hello Welcome to the Forums,

    Here is the code to add the new node to repeating node,

    Var userRowNode = XDocument.DOM.selectSingleNode("/my:myFields/dfs:dataFields/tns:getInstanceResponse/tns:getInstanceResult/d:workitem/d:tbl_User/d:tbl_UserRow");

    userRowNode.selectSingleNode("tbl_UserType").text = "Value of user type";

    userRowNode.selectSingleNode("tbl_UserComment").text = "Value of user comment";

    userRowNode.selectSingleNode("tbl_UserName").text = "Value of user name";

    Note: You have to check the prefix of above XPath should be correct and check once XPath also.

  • 12-16-2008 09:14 AM In reply to

    • Ulk31
    • Not Ranked
    • Joined on 12-16-2008
    • Posts 4

    Re: add values to repeating table of a WS with JScript, infopath 2003

    Hi Shiva,

     thank you very much for your quick response. I tried it, but I get the error:

    "not declared namespace-prefix: 'd'"

    something must be wrong at the end of the xpath
    ...tns:getInstanceResult/d:workitem/d:tbl_User/d:tbl_UserRow"

    Do you have any idea?

    Regards Ulk

  • 12-16-2008 09:56 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: add values to repeating table of a WS with JScript, infopath 2003

  • 12-17-2008 01:42 AM In reply to

    • Ulk31
    • Not Ranked
    • Joined on 12-16-2008
    • Posts 4

    Re: add values to repeating table of a WS with JScript, infopath 2003

    Hi,

    ok, I went through the links. My code looks like this now:

    >>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:q="http://schemas.microsoft.com/office/infopath/2003/ado/queryFields" xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-08T23:17:48" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:tns="http://tempuri.org/"');

    var userRowNode = XDocument.DOM.selectSingleNode("/my:myFields/dfs:dataFields/tns:getInstanceResponse/tns:getInstanceResult/d:workitem/d:tbl_User/d:tbl_UserRow");
    userRowNode.selectSingleNode("tbl_UserType").text = "Value of user type";
    <<

    The issue "not declared namespace-prefix: 'd'" seems to be solved but running the next line throws "'null' or not an object". Therefore I think something must be wrong in the xpath - right?

    Do you know where I can get information about the structure of a xpath? I don't know in which case I have to use my:, dfs:, tns: or d:.

    Thank you very much for your help!
    Regards Ulk

    Filed under: ,
  • 12-17-2008 04:58 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: add values to repeating table of a WS with JScript, infopath 2003

    Hello,

    You will get these namespace in your template.xml and myschema.xsd files. In these files you have structured and with prefix of the node names. Those namespace prefixes might be change in code also.

    If you are using InfoPath 2007,

    Open form in Design mode.

    Go to View -> Data Source.

    Select your field and right click on that field.

    Select ‘Copy XPath' option to select the path of the field.

    Paste into notepad or in your formcode.cs file.

    Go through the below links,

    http://lists.xml.org/archives/xml-dev/200507/msg00199.html

    http://msdn.microsoft.com/en-us/library/bb531390.aspx

  • 12-17-2008 05:38 AM In reply to

    • Ulk31
    • Not Ranked
    • Joined on 12-16-2008
    • Posts 4

    Re: add values to repeating table of a WS with JScript, infopath 2003

    Yeah, it works! Thank you very much for your help! The information to look in the template.xml helps a lot!

    for others... this is my running code now:

    >>
    XDocument.View.ExecuteAction("xCollection::insert", "tbl_UserRow_11");
    var userRowNode = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/tns:getInstanceResponse/tns:getInstanceResult/workitem/tbl_User/tbl_UserRow");
    userRowNode.selectSingleNode("tbl_UserType").text = "Value of user type";
    userRowNode.selectSingleNode("tbl_UserComment").text = "Value of user comment";
    <<

    My next step is to figure out how to select the other rows out of the tbl_User and not only the first . But I'll try to find this information in this forum.

    Thank's a lot again!
    Regards, Ulk

    Filed under: ,
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.