InfoPath 2007 Tips
To publish InfoPath forms to Sharepoint with time-stamped filenames:
- concat("Submission as at ", now()) as the filename in the publishing interface
- System.Environment.UserName to derive the logged-in username;
- thisXDocument.Role to derive the roles;
- thisXDocument.ViewInfos["View Name"] to get to the appropriate view;
- thisXDocument.DOM.selectSingleNode to select nodes based on the full XML document;
- docActionEvent.Source.selectSingleNode to select nodes based on the event parameter;
- Use ActiveX component to derive the domain and username if not using tools for office. Use ActiveXObject("Wscript.Shell") and the process environment.
- Calling web services from scripting code is not straight-forward and doing the same from the native InfoPath form without code is buggy!
- Monetary values should be dealt with using String instead of double as multiplication of double yields unexpected results
- 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