Geeks With Blogs

News invisible hit counter View My Stats
Technical Speaking

How to use formatting rules in Info Path 2010 by advance conditioning using userName() function and substring-before() & substring-after().

Scenario: I have a List Form customized by InfoPath Designer 2010 where set of rules applied based on business requirements. Another rule need to define that current user can only create item and can not do anything with the form after that if List Item created by him. It means Current user can not do anything in edit mode. Let’s think this is the basic requirement and how to do it. The real business case can be more complex! No matter. it will give you the idea how to solve this type of situation.

For Example:

A list item created by Contesto\Robert. if Robert try to edit list item after login then all fields will be disable so that Robert can do anything.

How to do that in the InfoPath form?

Solution:

You need the current logged user name and created by user name to compare and disable it using Add Rule.

Step 1: Select a Field in the form to setup Rule and set a condition for that.

Select Field –> Click Manage Rule –> Click New –> Click Formatting –> Set Condition –> Click “Select a field or group”

image

 

Step 2: You will get a Pop-Up to Select Account ID. Select the field and Press OK. It will return you

Contesto\Robert if List item created by Robert

Created_By

Step 3: Select Condition operator is “Is Equal To”

 

Step 4: Now you have to find the Current Logged User Name.

userName() is one of the important function to get Current logged user name from Info Path From. This will only return the Current User Account ID. Read this to know about formula function: userName() 

userName

Click on “use Formula” on the right field to get this. but it will not give the correct result as This function will return only username (Robert) without domain name. It means userName() will return Robert instead of Contesto\Robert.

There is a TRICK to solve this Smile.You have to use an Advance formula to get “Contesto\Robert”

concat(substring-before(AccountId, "\"), "\", userName())

Formula

How to build Formula:

substring-before(AccountId, "\") will return the Contesto. In the same way substring-after(AccountId, "\") will return Robert.

Concat is actually doing concat(“Contesto”,”\”, userName()) and finally return “Contesto\Robert”

So, if you use this formula to get Account ID or User Name with Doman then it will work perfectly.

 

Step 5: Complete the Rule after Select “Disable this control” and Re-Publish for

Disable

Now the field should be disable when Robert try to edit item which is created by him but enable for the others account.

Thank you.

Hope this will Help!

If you find this useful then post this link in your blog/twitter/group/etc.

Reference: http://office.microsoft.com/en-001/infopath-help/add-formatting-rules-HA101783371.aspx

MJ Ferdous

SharePoint Architect

Posted on Thursday, February 14, 2013 10:22 AM SharePoint 2010 | Back to top


Comments on this post: InfoPath 2010 formatting rules to compare with current logged user

# re: InfoPath 2010 formatting rules to compare with current logged user
Requesting Gravatar...
Thank you, this was helpful to me.
Left by Danni on Apr 24, 2014 12:31 AM

# re: InfoPath 2010 formatting rules to compare with current logged user
Requesting Gravatar...
Thank you! This is exactly what I was looking for.
Left by Adam on Jun 15, 2015 1:15 PM

# re: InfoPath 2010 formatting rules to compare with current logged user
Requesting Gravatar...
Thank you! Extremely useful post!
Left by Polina on Mar 18, 2016 9:24 PM

Your comment:
 (will show your gravatar)


Copyright © MJ Ferdous | Powered by: GeeksWithBlogs.net