Storing and reading ID of data set

I’m collecting some data from users via a form. Data is written into a collection upon submitting the form. I’m trying to look-up that same record on another page and hence would like to store the ID of this record in a variable. For some reason, the result of CurrentRecord is always ‘null’

Does anyone have an idea what I might be doing wrong?

My code looks like this:

local.clear() deletes ID before it is read. Try moving that line to right after let CurrentRecord
also you should probably only clear the unneeded key instead of the whole storage in case you set other keys down the road and forget about this code

import wixData from 'wix-data';
import {local} from 'wix-storage';

export function amount_click(event, $w) {
    let currentRecord = local.getItem('ID');
    local.removeItem('ID');
    local.setItem("RecordID", CurrentRecord);
    
    console.log(CurrentRecord);
}
1 Like