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 1 of 2 (23 items) 1 2 Next >
Sort Posts: Previous Next
  • 07-22-2008 07:56 AM

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

    The scenario:  We post forms to a sharepoint library for new projects, and extensions (of those once new projects).  Forms are submited as the form action.  I would like to keep the save feature as long as the status dropdownlist does not change (stays new or stays extension) because this would include changing data like error corrections.  However if a "new" announcement is opened and the status is changed to extension by the drop down, I would like to disable the save feature when this event happens. 

    Logic would be something like this:  when ddlStatus changes from New to Extension disable save

    Thanks in advance!!

     Oh, so is this possible at how and any step by step would be greatly appreciated.

  • 07-23-2008 12:42 AM In reply to

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

    Hi,

    If you are really looking to disable the save option of Infopath form,when the status of DDL changes from “New” to “Extension” ,I believe this can be done through VSTA Coding.Tools->Form Options->Open and Save(Category)->Save Behavour Section(Save using Custom Code)->Click on the  Edit button.It will open the VSTA Solution and event handler would be added for Save.This code executes when an user saves the form.Write below code in save Handler.public void FormEvents_Save(object sender, SaveEventArgs e){XPathNavigator root = MainDataSource.CreateNavigator();string ddlStatusValue = root.SelectSingleNode("XPATH to ddlStatus", NamespaceManager).Value;  //Check for ddlStatus valueif (ddlStatusValue.ToLower() == "extension")            {                e.CancelableArgs.Cancel = true;                e.CancelableArgs.Message = "U Cant Save";            e.CancelableArgs.MessageDetails = "U cant save as the status is Extension"; //if ddlStatus is Extension Don’t allow the user to save the form            }}Hope this works, fine !

     

    Thanks & Regards,
    Srikrushna Patro.
  • 07-23-2008 06:44 AM In reply to

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

    First off, thank you so much for posting this, and it appears this would work.  I want something a little different however.  I only want to disable save, if it changes from New to Extension. They could say, open a form that is already an extension and save it.  But if they open it and it's new, and change it to extension, the save would be disabled.  So is there a way to only trigger the save disabled event when ddlStatus value =new changes to ddlStatus value =extension? 

    Only on a change event if such a thing exists.  

     Thanks again!!!

     PS:  Since there are only the two options, a change event on that ddlStatus should do what I want.  I just have no idea how to program that.  Any takers?

  • 07-23-2008 07:44 AM In reply to

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

    I believe you are looking for the scenario, where the Save needs to disabled for the drop down value change from “New ” to “Extension”. If yes, hold on, the solution is pretty simple and look for the below code.//Create a reference variable of type boolean        public void ddlStatus_Changed(object sender, XmlEventArgs e)        {             string oldValue = e.OldValue;//collect the Old Value form Status drop down            string newValue = e.NewValue;//collect the New Value form Status drop down            //Check if the user changes the Drop down value from new to extension then only dont allow save otherwise            //let him for saving.            if (oldValue.ToLower() == "new" && newValue.ToLower() == "extension")            {                XPathNavigator root = MainDataSource.CreateNavigator();                root.SelectSingleNode("XPATH to ReferenceVariable", NamespaceManager).SetValue("true");            }//if the status changes, then set the referrence variable value to true.        }         public void FormEvents_Save(object sender, SaveEventArgs e)        {            //while saving the form,check if the reference variable is true.            //if true, dont allow user to save the form.            XPathNavigator root = MainDataSource.CreateNavigator(); string ddlStatusValue = root.SelectSingleNode("XPATH to ddlStatus", NamespaceManager).Value;            XPathNavigator root = MainDataSource.CreateNavigator();            string isTrue = root.SelectSingleNode("XPATH to ReferenceVariable", NamespaceManager).Value;            if (Convert.ToBoolean(isTrue))            {                e.CancelableArgs.Cancel = true;                e.CancelableArgs.Message = "U Cant Save";                e.CancelableArgs.MessageDetails = "U cant save as the status is Extension"; //if ddlStatus is Extension Don’t allow the user to save the form             }

            }

    This should suffice your requirement.
    Thanks & Regards,
    Srikrushna Patro.
  • 07-23-2008 08:40 AM In reply to

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

     Cool, that looks like it should work, however I'm getting the following error:

    Expected ';'
    File:script.js
    Line:95
    public void ddlEngagementType_Changed(object sender, XmlEventArgs e)

    Does this code need to be nested anywhere?  I currently have it sitting at the bottom of my page.  Thanks,

    Eric

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

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

    It seems VSTA programming language is set to JavaScript, however the discussion till now is Managed C# Code.Change the VSTA IDE’s programming language to C#.Let me guide you how to change the programming language of course to C#.Tools->Form Options->Programming->Choose the “form template code language” to C#.Now add the respective event handlers to the code and paste the above discussed code.That’s it! That can do the stuff what you are looking for!

     

    Thanks & Regards,
    Srikrushna Patro.
  • 07-24-2008 11:36 AM In reply to

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

     It's greyed out.  I dont have any code that I know of already write.  I have some data validation and rules, but i havent written no code like this.  Any I going to have to do this thing over?  You have been a tremendous help and I know we are almost there. Thanks,

  • 07-24-2008 11:42 AM In reply to

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

    You should be able to select the Remove Code button to remove any previously generated event handlers or code.

    Hilary Stoupa / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-24-2008 11:50 AM In reply to

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

     Sorry, I freaked out beore looking around.  Found my problem here:  http://support.microsoft.com/default.aspx?kbid=828853

    Thanks guys.  I'll test the code and let you know.

  • 07-24-2008 12:00 PM In reply to

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

     C#?  I only have JS and VBScript listed.  What do i do?

  • 07-24-2008 12:32 PM In reply to

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

     Srikrushna

    I'm starting to get the feeling this is specific to Infopath 2007.  Since I see C# listed in Infopath 2007 and it looks like the XmlEventArgs are part of the Microsoft.Office.Infopath namespace which MSDN says is in 2007.  I dont know what any of that means but I have a bad feeling in my stomach.  Can this be done in VBScript in 2003?    Thanks to anyone and everyone who reads this.

    Eric

  • 07-24-2008 01:47 PM In reply to

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

     Thanks for all your help but we can close this.  Since the users are opening the document from sharepoint and making the changes, even if we disable save, it's still going to prompt to save after they submit because the file has changes.  I just don't see anyway to get that to work.  

  • 07-25-2008 01:05 PM In reply to

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

     I can't give up that easily.  So I got Infopath 2007 and switched it to C# and I have inserted the code you supplied inserting the xpath to the dropdownlist.  One part i'm unsure of in your code is the xpath to the referencevariable.  what does that mean and what is it?

    Ex: string isTrue = root.SelectSingleNode("XPATH to ReferenceVariable", NamespaceManager).Value;

     

    Also, I get "The type or namespace name 'XMLEventArgs' and 'SaveEventArgs' could not be found."

  • 07-25-2008 01:11 PM In reply to

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

    You replace "XPATH to ReferenceVariable" with the xpath to the field you've added as boolean. Earlier, in the code connected to the drop down box, you set the value of a boolean field to true if certain conditions are met. The xpath to that field needs to go in quotes in place of the phrase "XPATH to ReferenceVariable".

    Hilary Stoupa / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-25-2008 01:32 PM In reply to

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

    Are you refering this this line?: 

    root.SelectSingleNode("XPATH to ReferenceVariable", NamespaceManager).SetValue("true");

     

     My entire coding is such:

    public void ddlEngagementType_Changed(object sender, XmlEventArgs e)

    {

    string oldValue = e.OldValue;//collect the Old Value form Status drop down

    string newValue = e.NewValue;//collect the New Value form Status drop down

    //Check if the user changes the Drop down value from new to extension then only dont allow save otherwise let him for saving.

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

    {

    XPathNavigator root = MainDataSource.CreateNavigator();

    root.SelectSingleNode(
    "XPATH to ReferenceVariable", NamespaceManager).SetValue("true");

    }

    //if the status changes, then set the referrence variable value to true.

    }

    public void FormEvents_Save(object sender, SaveEventArgs e)

    {

    //while saving the form,check if the reference variable is true.

    //if true, dont allow user to save the form.

    XPathNavigator root = MainDataSource.CreateNavigator();

    string ddlEngagementTypeValue = root.SelectSingleNode("//my:ddlEngagementType", NamespaceManager).Value;

    XPathNavigator root = MainDataSource.CreateNavigator();

    string isTrue = root.SelectSingleNode("XPATH to ReferenceVariable", NamespaceManager).Value; if (Convert.ToBoolean(isTrue))

    {

    e.CancelableArgs.Cancel = true;

    e.CancelableArgs.Message = "U Cant Save";

    e.CancelableArgs.MessageDetails = "U cant save as the status is Extension";

    //if ddlStatus is Extension Don’t allow the user to save the form

    }

    }

     

    Not sure what I'm looking for here.  I can do HTML but this stuff is a strech for me :-)

Page 1 of 2 (23 items) 1 2 Next >
Copyright © 2003-2007 Qdabra Software. All rights reserved.
View our Terms of Use.