I'm a SharePoint developer. I come across many issues that others will encounter. In this blog I keep a record of some of the interesting one. I just hope they can help others.
Saturday, October 13, 2012
How to setting values of InfoPath Textbox with jquery/javascript, json.
How to setting values of InfoPath Textbox with jquery/javascript, json.
Put this code in CEWP on a web part page containing an InfoPath Form Web Part.
Set delay, as InfoPath loads asynchronously, so document ready in jquery does not work.
window.onload = function()
{
window.setTimeout(readyCall, 1000);
}
then get reference
var textBoxEmployeeId = $("#ctl00_m_g_9053a19d_7ea2_49c3_9af1_11ab9e5bbca3_FormControl0_V1_I1_T2");
then call json endpoint
var url = "https://yourserver/endpoint?callback=?";
$.getJSON(url, null, function (data) {
textBoxEmployeeId.val(data["EmployeeNumber"]);
});
then set focus. This is VERY import in InfoPath, or else it will not presist or preserve the data
textBoxEmployeeId.focus();
In InfoPath set the postback options of the field to NEVER
This way you can call json, or other web services, and write the values to InfoPath
1st thing readyCall() is not found error.Then i defined that.
ReplyDeletethen i got "textBoxEmployeeId undefined error".
I need to set one text value to one control.How to do. Plz help
the $("#ctl00_m_g_9053a19d_7ea2_49c3_9af1_11ab9e5bbca3_FormControl0_V1_I1_T2") selector is not found because your selector will be different.
ReplyDeleteUser the web dev tools (usually F12 brings them up) to identify the necessary selector.