Setting value on submit - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Setting value on submit

Last post 10-02-2007 02:32 AM by B.Shiva Prasad. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 10-01-2007 06:19 AM

    Setting value on submit

    With the following code, I try to set 2 field values  (LastUpdated_by and LastUpdated_time) at the moment a custom submit button is pressed.

    function CmdSave::OnClick(eventObj)
    {
     var curDate = new Date()
     var sLastUpdated_by = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:EMPLOYEE_NOT_ON_SITE/@LastUpdated_by");
     var sLastUpdated_time = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:EMPLOYEE_NOT_ON_SITE/@LastUpdated_time"); 
     sLastUpdated_by.text = GetLogin();
     sLastUpdated_time.text =  curDate
     try
      {
      // save all changes made.
      XDocument.Submit();
      }catch(Oeps)
       {
       XDocument.UI.Alert("Er is een fout opgetreden: \n\n\tOfwel is er een verplicht veld niet ingevuld (rood *),\n\tOfwel is er een ongeldige waarde ingevuld (rode stippellijn)");   
       return;
       }
     var objEmail = XDocument.DataAdapters("Sendto2Approver")
     objEmail.Submit()
    }

    But it doesn't work. The variables sLastUpdated_by and sLastUpdated_time point to null. I'm sure one of you knows what I am doing wrong this time.

    Thanks in advance for your help.

     

    Hans.
    Infopath 2003 / Jscript
  • 10-01-2007 06:24 AM In reply to

    Re: Setting value on submit

    You have your assignments out of order.

    You set your field values before you GetLogin() and currDate.

    Try This...

    function CmdSave::OnClick(eventObj)
    {
     var curDate = new Date()

     sLastUpdated_by.text = GetLogin();
     sLastUpdated_time.text =  curDate
     var sLastUpdated_by = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:EMPLOYEE_NOT_ON_SITE/@LastUpdated_by");
     var sLastUpdated_time = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:EMPLOYEE_NOT_ON_SITE/@LastUpdated_time"); 

     try
      {
      // save all changes made.
      XDocument.Submit();
      }catch(Oeps)
       {
       XDocument.UI.Alert("Er is een fout opgetreden: \n\n\tOfwel is er een verplicht veld niet ingevuld (rood *),\n\tOfwel is er een ongeldige waarde ingevuld (rode stippellijn)");   
       return;
       }
     var objEmail = XDocument.DataAdapters("Sendto2Approver")
     objEmail.Submit()
    }

  • 10-01-2007 06:32 AM In reply to

    Re: Setting value on submit

    Thanks for the suggestion, but your code doesn't work.

    Anyhow I tought you first need to declare your variables before assigning a value. I think it has to see with the fact that this code is assigned to a button, the same thing works if it used in the 'onafterchange' event of a control.

    Regards

    Hans.
    Infopath 2003 / Jscript
  • 10-01-2007 06:40 AM In reply to

    Re: Setting value on submit

    You would need to debug, I often have an Alert with my variables fire at various points to be able to track their states.

    Have you verified your GetLogin() is working and set you curDate somewhere else?

  • 10-01-2007 06:52 AM In reply to

    Re: Setting value on submit

    GetLogin() is working fine, just like it should. After sLastUpdated_by = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:EMPLOYEE_NOT_ON_SITE/@LastUpdated_by") sLastUpdated_by seems to be 'null'  (I've seen in the Wath window) and cannot be assigned a value.

    XDocument.UI.Alert(GetLogin()) shows me the correct info.

    About the curDate thing I'm not sure, but I never get to that line in execution.

    Hans.
    Infopath 2003 / Jscript
  • 10-01-2007 07:19 AM In reply to

    Re: Setting value on submit

    Yah, Now going back and looking at your code you have it right.

    I would try specifying a value on your assignment. Set Last Updated by to "Bob" or something to verify this functionality.

    You could also add an alert on the IP field before and after too.

  • 10-02-2007 02:32 AM In reply to

    Re: Setting value on submit

    Hi stumbler,

    Once see the prefix for the attributes (LastUpdated_by, LastUpdated_time) in the XPath and then try again. I worked out with an example.

    Hope this will help you.

    B.Shiva Prasad
    InfoPath Dev,
    http://www.ggktech.com
    India
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.