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