Setting a default value on page load for a lookup dropdown

Hello,

On a new form, I'd like to set a default value on a lookup dropdown, this is what I have currently but doesn't seem to be working. Can you assist, please?

fd.spRendered(function(){
fd.field('OperatingHours').ready().then(function () {
//set Lookup field value once the field loads
fd.field('OperatingHours').value = '24x7';
});
});

Many thanks,
Dayna

Hello @Dayna,

You must know the item ID to set the lookup field value. For instance, the target item ID is 5 then you can use this code:

fd.spRendered(function() {
    fd.field('OperatingHours').ready().then(function() {
        //set Lookup field value once the field loads
        fd.field('OperatingHours').value = 5;
    });
});

Ah, so it always has to be the ID rather than the text of the value, got it - thank you!

1 Like

But doing so the lookup field shows desired value but its real value doesnt seems to be full legit lookup value, all other data like value.LookupValue is missingm so when i have 'onchange' method assigned for this lookup field which stores its LookupValue in other field this value ise empty, why?

@szymanskicode,

If you change the lookup field value programmatically, no additional data is loaded. You need to reload value:

fd.field('Lookup').value = 3;
fd.field('Lookup').reloadValue();
1 Like