Disable Save fetaure based on the changing of a drop down value. - InfoPath Dev Sign in | Join | Help in Code InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Code » Disable Save fetaure based on the changing of a drop down value. 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: Oldest to newest Newest to oldest Previous Next 07-22-2008 07:56 AM e_stylzz Joined on 07-11-2008 DE Posts 55 Disable Save fetaure based on the changing of a drop down value. Reply Contact 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 saveThanks in advance!! Oh, so is this possible at how and any step by step would be greatly appreciated. Filed under: code Vb notes submit sharepoint, save as, form, save, sharepoint 07-23-2008 12:42 AM In reply to srikrushna Joined on 03-28-2008 Posts 34 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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 e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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 srikrushna Joined on 03-28-2008 Posts 34 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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 e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact Cool, that looks like it should work, however I'm getting the following error:Expected ';'File:script.jsLine:95public 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 srikrushna Joined on 03-28-2008 Posts 34 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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 e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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 Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact You should be able to select the Remove Code button to remove any previously generated event handlers or code. Hilary Stoupa 07-24-2008 11:50 AM In reply to e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact Sorry, I freaked out beore looking around. Found my problem here: http://support.microsoft.com/default.aspx?kbid=828853Thanks guys. I'll test the code and let you know. 07-24-2008 12:00 PM In reply to e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact C#? I only have JS and VBScript listed. What do i do? 07-24-2008 12:32 PM In reply to e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact SrikrushnaI'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 e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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 e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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 Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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 07-25-2008 01:32 PM In reply to e_stylzz Joined on 07-11-2008 DE Posts 55 Re: Disable Save fetaure based on the changing of a drop down value. Mark as Not AnswerMark as Answer... Reply Contact 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-2019 Qdabra Software. All rights reserved.View our Terms of Use.
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.
Hi,
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?
}
Cool, that looks like it should work, however I'm getting the following error:
Expected ';'File:script.jsLine:95public 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
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,
You should be able to select the Remove Code button to remove any previously generated event handlers or code.
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.
C#? I only have JS and VBScript listed. What do i do?
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.
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.
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."
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".
root.SelectSingleNode(
My entire coding is such:
{
XPathNavigator root = MainDataSource.CreateNavigator();
e.CancelableArgs.Cancel =
e.CancelableArgs.MessageDetails =
Not sure what I'm looking for here. I can do HTML but this stuff is a strech for me :-)