Disable Save fetaure based on the changing of a drop down value. - InfoPath Dev
in

InfoPath Dev

Disable Save fetaure based on the changing of a drop down value.

Last post 07-29-2008 11:23 AM by e_stylzz. 22 replies.
Page 2 of 2 (23 items) < Previous 1 2
Sort Posts: Previous Next
  • 07-25-2008 01:37 PM In reply to

    Re: Disable Save fetaure based on the changing of a drop down value.

    Any place you see XPATH to Reference Variable, you need to replace those words with the xpath to your field. To get that, you can right click on the field in the data source and select Copy XPath. When I read this code, it tells me that in the Changed event for your drop down, if the drop down changes from "new" to "extension", another field is having its value set to "true" -- kind of  a helper field, if you will. XPATH to Reference Variable should be replaced with the XPath to that field.

    Hilary Stoupa

  • 07-25-2008 02:14 PM In reply to

    Re: Disable Save fetaure based on the changing of a drop down value.

    I'm not sure what that field is though (the helper field).  I'm just copying and pasting code that was provider earlier in this post.  Do i need to add a control of some sort? 
  • 07-25-2008 02:22 PM In reply to

    Re: Disable Save fetaure based on the changing of a drop down value.

    I realize you are just copying and pasting the code provided earlier. That code depends upon you having a boolean field that can be set to "true" when certain conditions are met. You don't have to add a control, you can just add another node to your schema in the Data Source Task Pane, and set its datatype to be a boolean. Here are some instructions on how to do that.

    Hilary Stoupa

  • 07-28-2008 05:14 AM In reply to

    Re: Disable Save fetaure based on the changing of a drop down value.

     Hilary, thanks for your patience.  I understand what you mean now and got that poriton setup.  I'm still getting run time errors with XmEventArgs and SaveEventArgs however.  They have the green squigley line under it and it says this when I rollover it:  "The type or namespace name 'XmlEventArgs' could not be found (are you missing a using directive or an assembly reference?)

    I'm using C#(InfoPath 2003 Compatible)

  • 07-28-2008 08:55 AM In reply to

    Re: Disable Save fetaure based on the changing of a drop down value.

     Looks like this has to be done in 2007 to use this code.  Any way to do this in 2003 or with 2003 compatible code? 

  • 07-28-2008 09:04 AM In reply to

    Re: Disable Save fetaure based on the changing of a drop down value.

    The code you are using is for the 2007 object model, to begin with. It will not work with the 2003 object model. Also, the code includes the event handlers, which you will need to add to your form and then use the code from the sample in the event handler you create. Here is an article on that.

    Hilary Stoupa

  • 07-28-2008 09:41 AM In reply to

    Re: Disable Save fetaure based on the changing of a drop down value.

     Yeah, thats how I figured out this was for 2007.  When I had 2003 compatible C#, the changed event was not available, but when i changed it to plain C# it became avaialble.  Is there anyway to do this in 2003 and would anyone be willing to volunteer the code if so?  I have a few books on the way, but this project is supposed to go live on Monday and I don't think i'll know that much by then. 

  • 07-29-2008 11:23 AM In reply to

    Re: Disable Save fetaure based on the changing of a drop down value.

    The following solution was thanks to Hilary Stoupa, Thank you!:

     I had to to create a boolean field first that would assist in the operation.  Then I created to event handlers.  One for the dropdownlist, and onAfterChange event, and one for saving, onSaveRequest.  Here is the code I used for the two of them:

    public void ddlEngagementType_OnAfterChange(DataDOMEvent e)

    //checks to see if the engagement type has changed from New to Extension. If so, it sets a boolean field to true

    //which will later disable save forcing a submit only. This prevents saving new extensions over current new project announcements.

    {

    // Write your code here to restore the global state.

    if (e.IsUndoRedo)

    {

    // An undo or redo operation has occurred and the DOM is read-only.

    return;

    }

    // A field change has occurred and the DOM is writable.

    // Write your code here.

    if (e.OldValue != null)

    {

    //set variables to hold the old value and the new value of the field

    string newValue = e.NewValue.ToString();

    string oldValue = e.OldValue.ToString();

    //if the field used to have the value of new and now has the value of extension, move into the next code block

    if (oldValue.ToLower().Equals("new") && newValue.ToLower().Equals("extension"))

    {

    //set our helper field to "true"

     

    thisXDocument.DOM.selectSingleNode("/my:myFields/my:ddlEngagementType/@my:bEngagementType").text = "true";

    }

    }

    }

     

    public void FormEvents_OnSaveRequest(SaveEvent e)

    //This checks the value of the helper boolean to determine if any of the triggers went off to disable save

    {

    // Write your code that will run before a Save or Save As operation here.

    //get the values of the drop down and the helper node

    string ddlValue = thisXDocument.DOM.selectSingleNode("/my:myFields/my:ddlEngagementType").text;

    string helper = thisXDocument.DOM.selectSingleNode("/my:myFields/my:ddlEngagementType/@my:bEngagementType").text;

    //check to see if our helper node is true -- if it is, and if the value of the drop down is "extension", don't allow saving

    if (Convert.ToBoolean(helper) && ddlValue.ToLower().Equals("extension"))

    {

    thisXDocument.UI.Alert(
    "You can't save the form because you changed the status from new to extension");e.ReturnStatus = true;

    }

    else

    {

    e.IsCancelled = e.PerformSaveOperation();

    // Write your code to be run after saving here.

    e.ReturnStatus = true;

    }

    }

     

    Hope this helps.  Thanks to all who contributed!

    Eric

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