Link to home
Start Free TrialLog in
Avatar of LessIsMore
LessIsMoreFlag for United States of America

asked on

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

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>
Avatar of Ramkisan Jagtap
Ramkisan Jagtap
Flag of Finland image

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/
ASKER CERTIFIED SOLUTION
Avatar of LessIsMore
LessIsMore
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LessIsMore

ASKER

My script worked