Populate Text box after form load - 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 » Populate Text box after form load Populate Text box after form load Last post 10-13-2010 09:32 AM by greenawayr. 11 replies. Page 1 of 1 (12 items) Sort Posts: Oldest to newest Newest to oldest Previous Next 09-23-2010 12:23 PM greenawayr Joined on 05-05-2009 Posts 52 Populate Text box after form load Reply Contact Hi, I have a form template based on a webservice. As part of the form load procedure, the form will try and submit a GUID to a database, if it doesn't contain a GUID, i.e. it's a blank form, then the webservice creates a row in the database table and the form populates it's datafields with the data in the new row. However, for this to work there must be a field that can retain the GUID that was created when the form was first created. Because the form is doing a round trip after the form load event, I'm having trouble getting the text box that will permanantly contain the form GUID, to populate and retain. I have tried using the Default Value function and creating a rule that sets a fields value and neither of these seem to work, presumably because the field needs an event to trigger it after the Form Load event. If I place it in one of the Optional Sections on the form, then when the Optional Section is inserted then the GUID will appear, however, because the Optional Sections relate to different tables, it is possible the row inserted in the table by the Optional Section, could be deleted and if this happens then the GUID would be gone and there would be no link. Basically I need to be able to populate a text box with the value of another text box after the Form Load event. Is there an event for when a field becomes populated with a value? Does this even need code? Thanks in advance 09-23-2010 12:59 PM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact Ideally coding in VB and think it would feed off the FetchGUID textbox Changed event, but not sure, and not great at coding. Thanks 09-24-2010 02:30 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact Having wasted a day and a half messing around with code on this, I found out that if I set the Default Value for the field in Tools>Default Values then it works. Could anyone explain the difference between setting the Default Value here, and setting the Default Value in the Data Source taskbar? 09-24-2010 02:39 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact I wonder if this has to do in some way with how IP is interpreting your data source from your web service? If your form isn't something you can't share, would you mind posting a sample here? I'd just like to see what the schema is like.... (you can post a file under the Options tab). Hilary Stoupa 10-05-2010 08:54 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Populate Text box after form load NBSForms.xsn Mark as Not AnswerMark as Answer... Reply Contact Hi Hilary, Having fixed this problem I now have a temperamental issue with another field. The field is in the main datasource and it's default value is set from a field in a secondary datasource. The problem doesn't seem to be the datasources as I have added a new field in the main datasource, but on the form as opposed to our database, and I can populate the exact GUID I want into this field. Yet I cannot get the field it should be populated in to work. AdviserGUID (Main Datasource) <-------- MappingGUID (secondary datasource) This doesn't work TempGUID (new field in main datasource) <-------- MappingGUID (secondary datasource) This does work but I still cant populate the AdviserGUID field. It worked earlier today, then whilst I was making changes to the form in an unrelated area, it seemed to stop working. I have checked the Logic Inspector and the only Logic there is what should be working. I've tried forcing it with some code behind but this didn't work either. Is it possible that my form/environment/Infopath is being temperamental? Has this happened to anyone else? My form is attached...I think. Thanks 10-05-2010 05:48 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact I'm having a little trouble locating the AdviserGUID field in your main data source -- what's the full XPath?That said, I do notice an odd rule on /dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Forms/ns1:ptAdviserGuid that makes me wonder if it could be at the heart of the issues you are having currently. Rules fire when a field changes. So, the rule on ptAdviserGuid will fire only when that field changes, and will set that field to a different value. Is that what you want? If that's the case, you may want to add rules to set fields when the query is run for the GetAdvisors data source instead.At any rate, let me know where the AdviserGUID and TempGUID fields are in the data source, and I can take a look at those. Hilary Stoupa 10-06-2010 02:17 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact Sorry Hilary, the field names I posted were just examples. The actual fields I am using are ptAdviserGUID (this is the field that should be getting populated but isn't), ptMappingGUID (this is the secondary datasource field "GetAdvisers" that should be dictating the value to ptAdviserGUID) and then I added an additional field called AdvisorGUID under my:advisers which proves that there is a value in ptMappingGUID and it can be set as a Default Value of another field, but for some reason it won't work for ptAdviserGUID. I have no rules set on my current form (which should be the form you're seeing) for ptAdviserGUID, simply it's Default Value being set as ptMappingGUID, I've checked the Logic Inspector for this as well. Could it be another field setting this rule and for some reason it isn't showing on the Logic inspector? 10-06-2010 03:39 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact Ok, I seem to be hitting upon the same problem as before. If I put the entire table that contains ptAdviserGUID on the form, it will not display the value, however, if I then click "Insert Item" in that repeating section, then the GUID appears. I overcame this problem last time by coding the changed event into a field which was created outside of the database, but was in the main datasource. However, trying this same trick results in a error on load System.NullReferenceExceptionObject reference not set to an instance of an object. at NBSForms.FormCode.AdviserGUID_Changed(Object sender, XmlEventArgs e) at Microsoft.Office.InfoPath.Internal.XmlEventHost.GenericProxy(Object genericDelegate, DataDOMEvent dataDOMEvent, InfoPathEvents type) at Microsoft.Office.InfoPath.Internal.XmlEventHost.ChangedProxy(DataDOMEvent dataDOMEvent) at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_SinkHelper.OnAfterChange(DataDOMEvent pDataDOMEvent) Having tried this on a number of fields that are in the Main Datasource and are part of the dataset that we retrieve on form load, the error keeps appearing, so I can only assume there is a problem with infopath code behind seeing these fields. Just to remind, that the fields that produce this error are created in a database, turned to an .xsd and connected to the form and the main datasource through a webservice. The fields that work are in the main datasource, but are created manually in Infopath in completely seperate groups. 10-06-2010 04:01 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact My thought would be that the value doesn't exist when you think it does -- that is, you say that the table that contains ptAdviserGUID "will not display the value" -- that indicates that the value isn't present when you believe it is -- does that make sense? As to your null reference exception, that again points to something not being present when you think it is -- have you tried debugging your code to see when and why you are getting the exception? Hilary Stoupa 10-11-2010 02:04 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact Hi Hilary, Having played around with it further, it seems the value can be added to this field, however, it requires some sort of event to fire it as it seems the sequence of events in the form load mean that when the webservice that populates this GUID runs after whatever I setup to place said GUID into the ptAdviserGUID field. If I add these fields onto the form as a repeating section, there is no GUID in the first section shown on the form, however, if I add a second section once the form has opened, the GUID appears correctly in the ptAdviserGUID field of the second section. This suggests to me that the GUID is available, but not at the point of the form load. Now given that this field must be filled in, what do you think would be the best way around this? Should it be working and am I missing something, or is it possible to fill this field on some sort of click event, perhaps the creation of all the Optional sections, one of which must be filled in, or perhaps, is it possible to place it in the Submit rules?Edit: I've gone through the code and in the Immediate window, when I break the program it shows that AdviserGUID.value has the correct GUID, however ptAdviserGUID is Referenced object has a value of 'Nothing' I've Copied the XPath from the datasource window so that should be correct. 10-13-2010 08:39 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact So, please excuse my being kind of slow (both to reply and in understanding!).... but this issue is occuring when you try to create a new form based on a web service? What happens if you just populate the GUID in the field programmatically on the form load instead of doing what you mention in your first post, where "the webservice creates a row in the database table and the form populates it's datafields with the data in the new row" Hilary Stoupa 10-13-2010 09:32 AM In reply to greenawayr Joined on 05-05-2009 Posts 52 Re: Populate Text box after form load Mark as Not AnswerMark as Answer... Reply Contact The GUID that we are trying to "force" into this field comes from a static table of advisers names and their respective GUID's. This was being queried by a secondary datasource and then the field with the GUID was meant to go into the ptAdviserGUID field, we tried Default Values, rules and programming, without luck. We've overcome this by placing the static table with the list of advisers, into the the XSD Dataset, and refreshing the datasource, so it became part of the Main Datasource, as soon as we did this we were able to populate the ptAdviserGUID field using the Default Value function. Not to worry about the slow reply. It seems either I was doing something stupid and overlooking a problem, or you simply cannot force a value from a secondary datasource into the main dataset at FormLoad, due to some sort of ordering. I'm sure a more knowledgable programmer would have figured it out, but our workaround seems to do the job. If you need clarification on what I did, for any other people who may come across this issue (unlikely I know), then just say. It's difficult to know if what I am saying makes sense to anyone else or not! Page 1 of 1 (12 items) Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
Hi,
I have a form template based on a webservice. As part of the form load procedure, the form will try and submit a GUID to a database, if it doesn't contain a GUID, i.e. it's a blank form, then the webservice creates a row in the database table and the form populates it's datafields with the data in the new row.
However, for this to work there must be a field that can retain the GUID that was created when the form was first created.
Because the form is doing a round trip after the form load event, I'm having trouble getting the text box that will permanantly contain the form GUID, to populate and retain. I have tried using the Default Value function and creating a rule that sets a fields value and neither of these seem to work, presumably because the field needs an event to trigger it after the Form Load event.
If I place it in one of the Optional Sections on the form, then when the Optional Section is inserted then the GUID will appear, however, because the Optional Sections relate to different tables, it is possible the row inserted in the table by the Optional Section, could be deleted and if this happens then the GUID would be gone and there would be no link.
Basically I need to be able to populate a text box with the value of another text box after the Form Load event. Is there an event for when a field becomes populated with a value? Does this even need code?
Thanks in advance
Ideally coding in VB and think it would feed off the FetchGUID textbox Changed event, but not sure, and not great at coding.
Thanks
Having wasted a day and a half messing around with code on this, I found out that if I set the Default Value for the field in Tools>Default Values then it works. Could anyone explain the difference between setting the Default Value here, and setting the Default Value in the Data Source taskbar?
I wonder if this has to do in some way with how IP is interpreting your data source from your web service? If your form isn't something you can't share, would you mind posting a sample here? I'd just like to see what the schema is like.... (you can post a file under the Options tab).
Hi Hilary,
Having fixed this problem I now have a temperamental issue with another field.
The field is in the main datasource and it's default value is set from a field in a secondary datasource.
The problem doesn't seem to be the datasources as I have added a new field in the main datasource, but on the form as opposed to our database, and I can populate the exact GUID I want into this field. Yet I cannot get the field it should be populated in to work.
AdviserGUID (Main Datasource) <-------- MappingGUID (secondary datasource)
This doesn't work
TempGUID (new field in main datasource) <-------- MappingGUID (secondary datasource)
This does work but I still cant populate the AdviserGUID field.
It worked earlier today, then whilst I was making changes to the form in an unrelated area, it seemed to stop working. I have checked the Logic Inspector and the only Logic there is what should be working. I've tried forcing it with some code behind but this didn't work either. Is it possible that my form/environment/Infopath is being temperamental? Has this happened to anyone else?
My form is attached...I think.
I'm having a little trouble locating the AdviserGUID field in your main data source -- what's the full XPath?
That said, I do notice an odd rule on /dfs:myFields/dfs:dataFields/tns:GetFormDatasetResponse/tns:GetFormDatasetResult/ns1:dsForms/ns1:Forms/ns1:ptAdviserGuid that makes me wonder if it could be at the heart of the issues you are having currently.
Rules fire when a field changes. So, the rule on ptAdviserGuid will fire only when that field changes, and will set that field to a different value. Is that what you want? If that's the case, you may want to add rules to set fields when the query is run for the GetAdvisors data source instead.
At any rate, let me know where the AdviserGUID and TempGUID fields are in the data source, and I can take a look at those.
Sorry Hilary, the field names I posted were just examples.
The actual fields I am using are ptAdviserGUID (this is the field that should be getting populated but isn't), ptMappingGUID (this is the secondary datasource field "GetAdvisers" that should be dictating the value to ptAdviserGUID) and then I added an additional field called AdvisorGUID under my:advisers which proves that there is a value in ptMappingGUID and it can be set as a Default Value of another field, but for some reason it won't work for ptAdviserGUID.
I have no rules set on my current form (which should be the form you're seeing) for ptAdviserGUID, simply it's Default Value being set as ptMappingGUID, I've checked the Logic Inspector for this as well.
Could it be another field setting this rule and for some reason it isn't showing on the Logic inspector?
Ok, I seem to be hitting upon the same problem as before. If I put the entire table that contains ptAdviserGUID on the form, it will not display the value, however, if I then click "Insert Item" in that repeating section, then the GUID appears. I overcame this problem last time by coding the changed event into a field which was created outside of the database, but was in the main datasource. However, trying this same trick results in a error on load
System.NullReferenceExceptionObject reference not set to an instance of an object. at NBSForms.FormCode.AdviserGUID_Changed(Object sender, XmlEventArgs e) at Microsoft.Office.InfoPath.Internal.XmlEventHost.GenericProxy(Object genericDelegate, DataDOMEvent dataDOMEvent, InfoPathEvents type) at Microsoft.Office.InfoPath.Internal.XmlEventHost.ChangedProxy(DataDOMEvent dataDOMEvent) at Microsoft.Office.Interop.InfoPath.SemiTrust._DataDOMEventSink_SinkHelper.OnAfterChange(DataDOMEvent pDataDOMEvent)
Having tried this on a number of fields that are in the Main Datasource and are part of the dataset that we retrieve on form load, the error keeps appearing, so I can only assume there is a problem with infopath code behind seeing these fields.
Just to remind, that the fields that produce this error are created in a database, turned to an .xsd and connected to the form and the main datasource through a webservice. The fields that work are in the main datasource, but are created manually in Infopath in completely seperate groups.
Having played around with it further, it seems the value can be added to this field, however, it requires some sort of event to fire it as it seems the sequence of events in the form load mean that when the webservice that populates this GUID runs after whatever I setup to place said GUID into the ptAdviserGUID field. If I add these fields onto the form as a repeating section, there is no GUID in the first section shown on the form, however, if I add a second section once the form has opened, the GUID appears correctly in the ptAdviserGUID field of the second section.
This suggests to me that the GUID is available, but not at the point of the form load.
Now given that this field must be filled in, what do you think would be the best way around this? Should it be working and am I missing something, or is it possible to fill this field on some sort of click event, perhaps the creation of all the Optional sections, one of which must be filled in, or perhaps, is it possible to place it in the Submit rules?
Referenced object has a value of 'Nothing'
I've Copied the XPath from the datasource window so that should be correct.
So, please excuse my being kind of slow (both to reply and in understanding!).... but this issue is occuring when you try to create a new form based on a web service? What happens if you just populate the GUID in the field programmatically on the form load instead of doing what you mention in your first post, where "the webservice creates a row in the database table and the form populates it's datafields with the data in the new row"
The GUID that we are trying to "force" into this field comes from a static table of advisers names and their respective GUID's. This was being queried by a secondary datasource and then the field with the GUID was meant to go into the ptAdviserGUID field, we tried Default Values, rules and programming, without luck.
We've overcome this by placing the static table with the list of advisers, into the the XSD Dataset, and refreshing the datasource, so it became part of the Main Datasource, as soon as we did this we were able to populate the ptAdviserGUID field using the Default Value function.
Not to worry about the slow reply. It seems either I was doing something stupid and overlooking a problem, or you simply cannot force a value from a secondary datasource into the main dataset at FormLoad, due to some sort of ordering. I'm sure a more knowledgable programmer would have figured it out, but our workaround seems to do the job.
If you need clarification on what I did, for any other people who may come across this issue (unlikely I know), then just say. It's difficult to know if what I am saying makes sense to anyone else or not!