await is only valid in async functions

Post Reply
congomonster
Member
Posts: 25
Joined: Wed Jul 03, 2013 5:40 pm
Location: Germany
Contact:

await is only valid in async functions

Post by congomonster »

Hi,

need some help with my "newbie" question. I'm new to scripting with NodeJS and switch. I played around with it.
i copied the example from the documentation.

Code: Select all

async function jobArrived(s, flowElement, job) {

  const outConnections = flowElement.getOutConnections();
  for (const connection of outConnections) {
    if (job.isFile() && connection.getName() === 'Freigabe-Ordner') {
      await job.sendTo(connection); // here it is
    };
  };

};
But this give me the error: await is only valid in async functions and the top level bodies of modules
What I'm doing wrong here? Can someone explain?

thanks
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: await is only valid in async functions

Post by freddyp »

I see nothing wrong. Have you followed the correct procedure of creating the JavaScript code and linking to it from Switch Scripter and saving the script?

It gives you that error. Where? In the Switch Messages?
congomonster
Member
Posts: 25
Joined: Wed Jul 03, 2013 5:40 pm
Location: Germany
Contact:

Re: await is only valid in async functions

Post by congomonster »

Yes, i think i linked it correctly. The errors shows up on switch internal webpage. And the file is routed to the problem folder. We have the Fall 2021 version installed by the way.
congomonster
Member
Posts: 25
Joined: Wed Jul 03, 2013 5:40 pm
Location: Germany
Contact:

Re: await is only valid in async functions

Post by congomonster »

I think it is working now. The SwitchScripter cashed the main.js fil under the roaming folder in Windows. I did a reconnect to the main.js file.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: await is only valid in async functions

Post by freddyp »

Check the webinars under 3 and 4 on this page:
https://www.enfocus.com/en/learn/switch#scripting.

In the first of these two webinars you will hear multiple times: whenever you save the main.js script file, you also have to save the script in Switch Scripter for the reason that you mention: the script is cached.

In the second webinar it is explained how scripts can be developed in a different way by working with script folders (and in that case there is no need to save the script in Switch Scripter every time).
Post Reply