Introduction Working on InfoPath form is an easy affair as long as, developers use it for the sole purpose of its creation (Creating a simple forms to capture data and publish them to a server for sharing). The moment this rule is broken, the increase in the complexity will be directly proportional to the features being implemented.
Problem and solution There are situations where you may need to perform some action based on the currently logged in User, the role of the user or some other parameter.
Recently, I was working on something which required us to do some UI validations based on the user logged in. We cannot directly use the user roles provided as the user names will be stored in a database and we need to set the UI according to the user preferences.
This is not a straight forward task in InfoPath (though, I dont want to call it tedious aswell) as InfoPath does not work that way.
So, we had to work on several work arounds and found a very simple alternative.
In the attached sample, you can type in the any username in the user name textbox and the dropdown will be disabled as soon as the username is identified as the current windows username.
Pretty simple code... just look at how simple InfoPath makes things.
//OnLoad() thisXDocument.DOM.selectSingleNode("//my:Alias").text = Environment.UserName;
you need to have a hidden control on the screen called Alias, and all the control for which we have to control the state should be using the Alias control to set the rules
Summary Please get back to if you have any suggestions/comments/clarification regarding this topic. Write to me for the sample code for this article
|
No responses found. Be the first to respond and make money from revenue sharing program.
|