How to import functions from site FE package

How can I write site-wide functions and import them in certain pages? These functions should be able to use the session from the “wix-storage” module, so probably cant be in the backend. I tried putting it in the “Site” module of FE but cant find how to access that module from the page code.

What’s preventing you from writing a function on your backend or public file and importing it where needed.

Also it really depends what you are trying to do, if you want to interact with your collections or APIs using dynamic content from different pages then writing functions on the backend/public files can work.

If you tell us what your goal is then maybe we can provide a solution.

The main goal was to make a mutli-steps form where each input in the form is in a seperated page. In order to do so, I create a new row in the db when the user starts the form and saved the id of that object in the browser session. I didnt put it in the backend because I figured that the backend doesnt have access to the browser’s session (am I wrong?).
This is how it looks in the first input page:

import wixData from "wix-data";
import {session} from 'wix-storage';

function updateQuestionnaire (column_name, value) {
wixData.get("Questionnaire", session.getItem("currentQuestionnaireId"))
.then( (item) => {
console.info("updating questionnaire")
item.setAtrribute(column_name, value);
wixData.update("Questionnaire", item);
console.info("item updated");
console.info(item.protection_type);
} )
.catch( (err) => {
let errorMsg = err;
} );
}
$w.onReady(function () {
function clickHandler () {
console.info("1")
updateQuestionnaire('technology_field', $w("#radioGroup1").value);
}
$w("#button1").onClick(clickHandler);
});

#button1” is the next button, and im trying to have it update the row in the db with the value from “#radioGroup1”. Its currently not working (im still not sure why - i am new to javascript), but I once I figure it out, I would like the updateQuestionnaire function to be somewhere that I can import it in all the pages and not have to re-write it.

Any suggestions to why this is not working and where I can put the updateQuestionnaire functin will be happily accepted :slight_smile: