Dropdown Lookup field - Set default value

Plumsail Forms version: 2.0.7

Hi, I've been looking around and cant find a solution.
I'm trying to set a default value for a dropdown lookup field.
Basically, I would like to loop through all the IDs from the and set the field to the latest (basically, the last ID/record created).

Fyi, in the dropdown field, I'm showing the title, but would loop through and find the latest ID.

Any help is appreciated.

Luc

Dear @Stpie_l,
It's possible to send a pnpjs request to the lookup source list, find the item with the latest ID, and use it to set the lookup field value, try this:

fd.spRendered(function() {
    fd.field('Lookup').ready(function(){
        pnp.sp.web.lists.getByTitle('Source List').items.get().then(function(items){
             fd.field('Lookup').value = items.pop().ID;
        })
    });
});

Exactly what I was looking for. Wow that was a quick answer.
Is it also possible to to check if the record of the ID is still Active? There's a column in the Source List called Active.
Thanks in advance.
Luc

Dear @Stpie_l,
Try adding a filter, for example:

fd.spRendered(function() {
    fd.field('Lookup').ready(function(){
        pnp.sp.web.lists.getByTitle('Source List').items.filter("Active eq 1").get().then(function(items){
             fd.field('Lookup').value = items.pop().ID;
        })
    });

Thanks for the help. I'll need to read more on these pnpjs requests. Didnt know you could do this.
Luc

Dear @Stpie_l,
Here, you can check official documentation - List Items - PnP/PnPjs
For filtering, check Microsoft's docs - Use OData query operations in SharePoint REST requests | Microsoft Learn