Hi Rebecca Gordon
I don't recall having to set a lookup field through JavaScript before so can't provide much of an input.
But Set value of lookup field might be helpful as it seems like you might need to set two things in the Javascript for lookup fields.
Cheers
John
Hi John, thanks for your help
I think the issue is just the form loading, I managed to get it working using a button click after the page is loaded, but neither document ready or the RegisterAfterReady function work... I tried finding an easier way to set the default value for a lookup list, both in SharePoint and Nintex but can't see any option anywhere, do you know of one?
NWF.FormFiller.Events.RegisterAfterReady(function(){
NWF$("#"+jsLeaveTypeClientID).val('1');
NWF$("inputWid='" + jsLeaveTypeClientID + "']").val(NWF$("#" + jsLeaveTypeClientID + " option:selected").val());
});
Unfortunately, I'm not too sure with how it works in Office 365, it's probably worth contacting Nintex to clarify.
I can't access the script that we developed at the moment, but from my memory, we ended up having both the document ready and register after ready function (I can't remember the order). It seems overkill but for some reason we had to do that.
So, still no luck or answers. I have resorted to dirty old polling JavaScript. This code is tested and working:
function PollLeaveType() {
var endTime = Number(new Date()) + 20000; // try for 20 seconds
var interval = 500;
(function p() {
// If the condition is met, we're done!
if(LeaveTypeLoaded()) {
NWF$("#"+jsLeaveTypeClientID).val('1'); // set to annual leave which is always value 1
return;
}
// If the condition isn't met but the timeout hasn't elapsed, go again
else if (Number(new Date()) < endTime) {
setTimeout(p, interval);
}
else {
// don't set the default value, the user will have to set
return;
}
})();
}
function LeaveTypeLoaded()
{
// "" is the default value for "Please select a value..."
if (NWF$("#"+jsLeaveTypeClientID).val() == "")
return true;
else
return false;
}
PollLeaveType();
Thank you Rebecca, really helped me out! Hopefully Nintex will add an event to hook into to indicate when these fields are fully loaded soon!