ID as primary field

Hi friends! i use the following code to take the id and use it as primary for my data set. The problem is that if i want to create a dynamic item page , the entire row is blank . But … if you manually modify the empleoID entry in database , the dynamic page link appears in database . any solution ?

export function Empleoscompartidos_afterQuery(item,) {

    item.empleoID = item._id;
 
    return item;
    

    

}

I’m not sure I fully understand what you did there.
But: I don’t think your code does what you wanted it to do.
Try:

export function Empleoscompartidos_afterInsert(item, context) {
    item.empleoID = item._id;
    return item;
}

And the dynamic URL should appear in the collection content manager for all the new entries.

If you wish to update existing records created before you added the _afterInsert hook. do something like:

export async function Empleoscompartidos_afterQuery(item, context) {
if(!item.empleoID){
 item.empleoID = item._id;
await wixData.update('Empleoscompartidos', item, {suppressAuth:true, suppressHooks:true});
}
    return item;
}

@jonatandor35 it worked!!! you do not know the amount of post I read on this subject. None is resolved. Thanks to you many people will be able to solve the big problem of the ID thank you very much!!!:grin: