CMS update in automation Velo code?

Sorry I am a complete noob when it comes to automation payload code.

What I need is very simple! on payment successful update variables in CMS.

How do I update variables in CMS using automation feature?

My noob code below does not work!

import wixData from ‘wix-data’;
/**

  • Autocomplete function declaration, do not delete
  • @param {import(‘./schema.js’).Payload} options
    */
    export const invoke = async ({payload}) => {

const Lim = “Limit”;
const LimID = “SINGLE_ITEM_ID”;

wixData.get(Lim, LimID)
.then((item) => {

let toUpdatevar = {

“Var1”: 5,
“var2”: 45,
“var3”: item.var3 + 3,

};

wixData.update(“Limit”, toUpdatevar)

})
return {} // The function must return an empty object, do not delete
};

Anyone knows how to update cms with automation I would greatly appreciate it!

There is very little documentation and I never did any automation or async functions before.

If its done in another way that I don’t know please tell me as well.

Hey there,

Check this out:

Ok its solved updating CMS with automation is very easy.

Just await a function and add it to the bottom after the code!

import wixData from ‘wix-data’;

export const invoke = async ({payload}) => {

await updatedata()

return {}
};

function updatedata(){

const Lim = “Limit”;
const LimID = “SINGLE_ITEM_ID”;
wixData.get(Lim, LimID)
.then((item) => {

let toUpdate69 = {

“limit1”: item.limit1,
“limit2”: item.limit2,
“limit3”: item.limit3,
“limit4”: item.limit4,
“limit5”: item.limit5,
“limit6”: item.limit6,
“Mon”: item.Mon + 5,
“support”: item.support + 1,

};

wixData.update(“Limit”, toUpdate69)
})
}