Access Database Field in JScript - InfoPath Dev
in

InfoPath Dev

Access Database Field in JScript

Last post 11-24-2008 01:49 PM by AliMalek. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 11-19-2008 01:11 PM

    Access Database Field in JScript

    Hi,

    I am new to Infopath. So far, I designed a form to list contacts and it works. Now, I need to be able to delete a table row using the follwoing code.  SQLComplexDBID is the primary key but probably I have wrong syntax here because I am getting error after clicking on delete button. I checked the query in SQL profiler and it is delete dbo.SQLComplexDB where SQLComplexDBID = . Meaning that the primary key is not added to the query and executed.

    Can you please help? I attached my form.

    function btnDelete::OnClick(eventObj)

    { var SQLComplexDBID = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:SQLComplexDBList[@SQLComplexDBID]").text;

    XDocument.QueryAdapter.Command = "delete dbo.SQLComplexDB where SQLComplexDBID = " + SQLComplexDBID;

    XDocument.Query(); }

     Thanks

    Ali

  • 11-19-2008 09:29 PM In reply to

    Re: Access Database Field in JScript

    Hi,

    Do you want to get the ‘SQLComplexDBID' value then the xpath you are using is not correct. Use the following xpath to get the SQLComplexDBID value.

    function btnDelete::OnClick(eventObj)

    {

     var SQLComplexDBID = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:SQLComplexDBList/@SQLComplexDBID").text;

    if(SQLComplexDBID != null)

    {

    XDocument.QueryAdapter.Command = "delete dbo.SQLComplexDB where SQLComplexDBID = " + SQLComplexDBID;

    XDocument.Query();

    }

     }

    Swathip
    www.ggktech.com
  • 11-20-2008 06:48 AM In reply to

    Re: Access Database Field in JScript

    Thanks. It worked.

  • 11-20-2008 07:46 AM In reply to

    Re: Access Database Field in JScript

    Sorry more questions:

    As you can see in attached screenshot, I have a repeating table that lists contacts for each database I manage. For each row of the table, I put a Delete button for users to remove the contact. In preview form, when I click on Delete button, I always see the first row being deleted even when I click on Delete button in 2nd and third rows. Here is the code I use to delete. What am I doing wrong?

    function btnDeleteAppContact::OnClick(eventObj)

    { var AppContactID = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:SQLComplexDBList/@AppContactID").text;

    if(AppContactID != null) {

    XDocument.QueryAdapter.Command = "delete dbo.AppContact where AppContactID = " + AppContactID;

    XDocument.Query(); } }

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

    How can I add a Confirm Delete popup window before actually deleting a row? I am new to JScript?

     Thanks

    Ali


  • 11-20-2008 10:02 PM In reply to

    Re: Access Database Field in JScript

    Hi,

    In the above code, every time you are getting the first ‘AppContactID'. Instead of that get the current row AppContactID. For that use the following code line.

    var AppContactID = e.source.selectSingleNode("@AppContactID").text;

    You can add confirm messages using the following code.

    var answer = confirm ("Write the confirm message here")
    if (answer)
    //Continue with your code else
    return

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

    Re: Access Database Field in JScript

    Thanks Swathip.

     What is e (e.source.selectSingleNode) in your code? I am getting 'e' is undefined when I preview the form.

  • 11-21-2008 04:04 PM In reply to

    Re: Access Database Field in JScript

    Use eventObj.source instead. I believe in C# the variable is e.

    Hilary Stoupa

  • 11-24-2008 01:09 PM In reply to

    Re: Access Database Field in JScript

    I am getting 'source' is null or not an object.

    Here is my code:

    function btnItemDelete::OnClick(eventObj) {

    var AppContactID = eventObj.source.selectSingleNode("/dfs:myFields/dfs:dataFields/d:SQLComplexDBList/@AppContactID").text;

    Any idea why?

    Thanks

  • 11-24-2008 01:18 PM In reply to

    Re: Access Database Field in JScript

    Sorry -- source is capitalized: eventObj.Source

    Hilary Stoupa

  • 11-24-2008 01:49 PM In reply to

    Re: Access Database Field in JScript

    Thanks. That did it.

    Sorry one more question:

    After clicking on insert item in repeating section, how do I actually save new values in SQL Server? How do I access data fields entered by user?

     

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