Populate InfoPath 2013 form with user information using JQuery and SPservices.

LessIsMore
LessIsMore used Ask the Experts™
on
I have been looking hi and low to auto populate user name and department in InfoPath browser form from several sources available
I tried User Profile Service but since Microsoft made it difficult in 2013 version and I am not an admin on the host I can't use this.
 I also tried User Information list. It worked perfectly in InfoPath preview but came up empty when I published the form.

So I tried to use JQuery and SP services. I captured all info in alarms correctly but cant figure out how actually place it in form controls. I use text boxes for all.
<script src="/sites/MySite/SiteCollectionDocuments/jQuery/jquery-1.8.2.min.js" type="text/javascript"></script><script src="/sites/MySite/SiteCollectionDocuments/jQuery/jquery.SPServices-2014.01.min.js" type="text/javascript">
</script><script type="text/javascript">

$(function() {        
     var thisUsersValues = $().SPServices.SPGetCurrentUser({
      fieldNames: ["Title", "EMail", "Office", "WorkPhone"],
      debug: false
});
alert(thisUsersValues.EMail);


alert(thisUsersValues.Title);
alert(thisUsersValues.Office);

alert(thisUsersValues.WorkPhone);

$('textarea[title="WorkPhone"]').thisUsersValues.WorkPhone;
$('input[title="WorkPhone"]').thisUsersValues.WorkPhone;
});
</script>
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ramkisan JagtapLead Developer

Commented:
InfoPath Form Services won't let you publish an InfoPath form with JavaScript.
So using User Information list is a good option. There might be something that you missed.

Please check following blog to verify it.
http://www.ilikesharepoint.de/2013/01/infopath-20102013-userinformationlist-query-for-current-logged-in-user/
Ramkisan,
I actually made it.
The trick was to substitute the
'input[title="WorkPhone" to ID of the field. Example
$("input[id$='ctl00_ctl40_........._FormControl0_...._T2']").val(thisUsersValues.EMail);
Got it from using F12 on the page.
Thanks for your input.
 I did not use user information list because it does not authenticate people who are first time on the site and belong to the group. Most of my clients will belong to a group.

Author

Commented:
My script worked

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial