InfoPath 2007 Tips

To publish InfoPath forms to Sharepoint with time-stamped filenames:
  1. concat("Submission as at ", now()) as the filename in the publishing interface
To develop using Tools for Office SDK for InfoPath, make use of these:
  1. System.Environment.UserName to derive the logged-in username;
  2. thisXDocument.Role to derive the roles;
  3. thisXDocument.ViewInfos["View Name"] to get to the appropriate view;
  4. thisXDocument.DOM.selectSingleNode to select nodes based on the full XML document;
  5. docActionEvent.Source.selectSingleNode to select nodes based on the event parameter;
  6. Use ActiveX component to derive the domain and username if not using tools for office. Use ActiveXObject("Wscript.Shell") and the process environment.
  7. Calling web services from scripting code is not straight-forward and doing the same from the native InfoPath form without code is buggy!
  8. Monetary values should be dealt with using String instead of double as multiplication of double yields unexpected results
  9. GST multiplication may be as complicated as using string manipulation
concat(substring-before((. * 0.07), "."), ".", substring(substring-after((. * 0.07), "."), 1, 2))

var wshShell = new ActiveXObject("Wscript.Shell");
var wshEnv = wshShell.Environment("Process");
var username = wshEnv.Item("UserName");
var domain = wshEnv.Item("UserDomain");
var usernameElement = XDocument.DOM.selectSingleNode("//my:Username");

var fullLogin = domain + "\\" + username;
//XDocument.UI.Alert("Found Domain User: " + fullLogin);
usernameElement.text = fullLogin;
var getUserInfoDao = XDocument.DataObjects("GetUserInfo");
getUserInfoDao.DOM.setProperty("SelectionNamespaces", "xmlns:tns='http://schemas.microsoft.com/sharepoint/soap/directory/'");
getUserInfoDao.DOM.setProperty("SelectionLanguage", "XPath");
var inputParam = getUserInfoDao.DOM.selectSingleNode("//tns:GetUserInfo/tns:userLoginName");
inputParam.text = fullLogin;
var getUserInfoAdapter = getUserInfoDao.QueryAdapter;
getUserInfoAdapter.Query();
var username = getUserInfoDao.DOM.selectSingleNode("//tns:GetUserInfoResult/tns:GetUserInfo/tns:User/@Name").value
var preparedByNameElement = XDocument.DOM.selectSingleNode("//AuditTrail/PreparedBy/Name");
preparedByNameElement.text = username;

Comments

Anonymous said…
Great post, I am almost 100% in agreement with you

Popular posts from this blog

Understanding ITIL Service Management the UML way…

How to depict (Professional-Looking) Logical Network Diagrams in Astah