Showing posts with label InfoPath Forms Services 2007. Show all posts
Showing posts with label InfoPath Forms Services 2007. Show all posts

Friday, August 14, 2009

infopath form quick note

Note: When a form has a dropdown from a reference list in SharePoint, changing the values of the reference list does NOT change the selected values in the existing forms....which is an excellent thing.

Tuesday, March 24, 2009

Generate Unique ID for InfoPath form

We are going to generate a Unique ID for each InfoPath form using a SharePoint list. We will then use this ID as the unique filename.
1. Create a SharePoint list with a key column:


2. Each time we load the InfoPath form, we will grab the key and then increment the key by 1:
XPathNavigator xNav = MainDataSource.CreateNavigator();

XPathNavigator nodeTermid = xNav.SelectSingleNode("my:myFields/my:TermID",
NamespaceManager);

if (nodeTermid.InnerXml == "0")
{

string termid = getTermID();
nodeTermid.SetValue(termid);
….
}


private string getTermID()
{
string termSite = ConfigurationManager.AppSettings["url_termsite"].ToString();
string termIDListName = ConfigurationManager.AppSettings["list_termid"].ToString();
string termIDKey = string.Empty;

SPSite mysite = null;
SPWeb site = null;

try
{
mysite = new SPSite(termSite);
site = mysite.RootWeb;
site.AllowUnsafeUpdates = true;

SPList list = site.Lists[termIDListName];

SPQuery query = new SPQuery();
string queryText = "<Where><Eq><FieldRef Name='{0}'" +
"/><Value Type='Text'>{1}</Value></Eq></Where>";

queryText = string.Format(queryText, "Title", "termid");

query.Query = queryText;


SPListItemCollection results = list.GetItems(query);
foreach (SPListItem item in results)
{
termIDKey = item["key"].ToString();
}

int newID = Convert.ToInt32(termIDKey) + 1;

UpdateFieldValues(termIDListName, "key", newID.ToString(), "Title", "termid");

return termIDKey;
}
catch (Exception ex)
{

throw ex;
}
finally
{
if (mysite != null) mysite.Dispose();
if (site != null) site.Dispose();
}
}

public static void UpdateFieldValues(string listName, string attribute, string attrValue,
string filterField, string filterValue)
{
SPSite mysite = null;
SPWeb site = null;

try
{

mysite = new SPSite(ConfigurationManager.AppSettings["url_termsite"].ToString());
site = mysite.RootWeb;
site.AllowUnsafeUpdates = true;

SPList list = site.Lists[listName];

SPQuery query = new SPQuery();
string queryText = "<Where><Eq><FieldRef Name='{0}'" +
"/><Value Type='Text'>{1}</Value></Eq></Where>";

queryText = string.Format(queryText, filterField, filterValue);

query.Query = queryText;

SPListItemCollection results = list.GetItems(query);
foreach (SPListItem item in results)
{

item[attribute] = attrValue;
item.UpdateOverwriteVersion();
}

}
catch (Exception ex)
{
throw ex;
}
finally
{
if (mysite != null) mysite.Dispose();
if (site != null) site.Dispose();
}
}

Wednesday, April 16, 2008

infopath dataconnection: AllowOverWrite="0"

If you don't allow overwrite of the form with the same name, it would cause an error 'an error occurred while submitting the form' if there exists an infopath form of the same name.

Soln: use the now() function to make the filename unique. cheesy but a quick fix if you don't care about the name.

Wednesday, March 12, 2008

After updating Infopath Browser Enabled Form Template, new field became read-only on old/existing forms

Problem: After updating Infopath Browser Enabled Form, the newly added field became read-only on old forms. If you open the existing forms in notepad, you will not see your new field in the xml.

Soln: This happens when you choose 'Do nothing' on version upgrade. To make the fields selectable/editable, republish the form with the following options. Go to Tools -> Form Options -> Versioning -> On version upgrade, choose "Automatically upgrade existing forms". Once the new version is uploaded in Central Admin, go back to your old forms, you should see your new fields as editable.

Monday, February 4, 2008

Message: Cannot open log for source 'ExceptionManagerInternalException'. You may not have write access.

Message: Cannot open log for source 'ExceptionManagerInternalException'. You may not have write access.

Came across this message when trying to write to the event log using Microsoft.ApplicationBlocks.ExceptionManagement.dll in the Infopath (IFS) form codebehind. However, if you are an administrator of the box (web server where this is running on), you won't have a problem writing to the event log. Since we cannot grant all users administrator rights, that option is out.

Solution: by default, a sharepoint site uses impersonation. Use the SPSecurity class:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
ExceptionManager.Publish(ex);

});

As a side note, do not mess with the existing settings in web.config of the sharepoint site. Taking out impersonate="true" messed up our BDC and other things....

Infopath Submit Error

Came across this error today while trying to use ExceptionManager to write to the eventlog:
Message: The form cannot be submitted to the following location: http://d7014yleimoss:2007/Investments/10118.xml. There is a problem with the Web server. Make sure the Web server exists, try again later or contact the Web server administrator.

Happily this didn't take me time to figure out.

Solution: The user role was created to be able to submit the form, BUT the user was not granted 'contribute' access to to the Forms Library 'Investments'. Grant the logon user the 'contribute' access in the Forms Library Settings and the form submitted successfully.

Thursday, January 3, 2008

This form template is browser-compatible, but it cannot be browser-enabled on the selected site !!!

Get error:
This form template is browser-compatible, but it cannot be browser-enabled on the selected site
when trying to published a full-trust infopath browser enabled form.

Soln: must activate Office SharePoint Server Enterprise Site Collection features
(Features such as the business data catalog, forms services, and Excel Services, included in the Office SharePoint Server Enterprise License) from the Central Admin site also, besides the site feature and site collection that you are publishing to

Central Administration > Site Settings > Site Features
activate Office SharePoint Server Enterprise Site Collection features

Tuesday, October 30, 2007

Infopath form upload, stuck on installing, upgrading etc

Problem: This is a new issue that suddently happened after I published a form with databinding issues (trying to use dynamic links). After going to 'Manage Form Templates' in Central Administration, Application Management, the form is stucked on upgrading. Checked Operations -> Timer job definitions, and status, try to delete the job and redo to no avail.

Solution: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN>stsadm.exe -o execadmsvcjobs

Infopath browser form - test from client, doesn't see properties show up on sharepoint list/library

Problem: when testing from the client with the infopath form, submitting to sharepoint library, only see the name column, none of the properties seemed to be populated/promoted. On the repair documents/relink documents page, shows up as the 'Form' content type instead of the 'Investment' content type. (Investment is the content type of the published form.)

Soln: Steps to resolve: check the site content type, make sure the default content type is Investment, not Form. Reset IIS, resubmit from client should see the properties.