LessIsMore
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/SiteCol lectionDoc uments/jQu ery/jquery -1.8.2.min .js" type="text/javascript"></s cript><scr ipt src="/sites/MySite/SiteCol lectionDoc uments/jQu ery/jquery .SPService s-2014.01. min.js" type="text/javascript">
</script><script type="text/javascript">
$(function() {
var thisUsersValues = $().SPServices.SPGetCurren tUser({
fieldNames: ["Title", "EMail", "Office", "WorkPhone"],
debug: false
});
alert(thisUsersValues.EMai l);
alert(thisUsersValues.Titl e);
alert(thisUsersValues.Offi ce);
alert(thisUsersValues.Work Phone);
$('textarea[title="WorkPho ne"]').thi sUsersValu es.WorkPho ne;
$('input[title="WorkPhone" ]').thisUs ersValues. WorkPhone;
});
</script>
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/SiteCol
</script><script type="text/javascript">
$(function() {
var thisUsersValues = $().SPServices.SPGetCurren
fieldNames: ["Title", "EMail", "Office", "WorkPhone"],
debug: false
});
alert(thisUsersValues.EMai
alert(thisUsersValues.Titl
alert(thisUsersValues.Offi
alert(thisUsersValues.Work
$('textarea[title="WorkPho
$('input[title="WorkPhone"
});
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
My script worked
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/