If you want to select your lookup field on form load or other events you can use this script.
$(document).ready(function(){
var requeststudentId = '{{ request.params.id }}';
if(requeststudentId)
{
var eventLookupfilteroption = "studentid eq guid'"+requeststudentId+"'";
var odataUrI = "https://yourpotal.com/_odata/students?$filter="+encodeURIComponent(eventLookupfilteroption);
$.ajax({
type:'GET',
contentType: 'application/json; charset=utf-8',
datatype: 'json',
url: odataUrI,
beforeSend: function(XMLHttpRequest){
XMLHttpRequest.setRequestHeader('Accept', 'application/json');
},
async: true,
success: function(data, textStatus, xhr){
if(data.value[0]) {
// Populate lookup field
var studentid = data.value[0].studentid;
var studentid_name = data.value[0].proevt_name;
var studentid_entityname = "student";
$("#studentid").attr("value",studentid);
$("#studentid_name").attr("value",studentid_name);
$("#studentid_entityname").attr("value",studentid_entityname);
// Populate other field
var eventCode = data.value[0].studentcode;
var studentstartdatetime = data.value[0].studentstartdatetime;
var studentenddatetime = data.value[0].studentenddatetime;
var proevt_freeregistrations = data.value[0].proevt_freeregistrations;
$('#studentcode').val(eventCode);
$('#studentstartdatetime_datepicker_description').val(studentstartdatetime);
$('#studentenddatetime_datepicker_description').val(studentenddatetime);
$('#proevt_freeregistrations').val(proevt_freeregistrations);
}
},
error: function (xhr, textStatus, errorThrown ){
alert(textStatus+ ''+errorThrown);
}
});
}
});
Comments
Post a Comment