Script with arguments

Hi,
I have a script with arguments (overview or dayview).
How can I now start the script directly in Scriptable.
With the 3 following commands it does not work because the arguments are missing.

const params = JSON.parse(args.widgetParameter);
const show_overview = params.view ? params.view === “overview” : true;
const show_dayview = params.view ? params.view === “dayview” : true;

Thanks

If I understand you correctly, maybe use this:

if(args.widgetParameter == null) 
{		
	// Specify some default values.
}
else
{
	// Use the widget parameter values.
}

Hi,
thanks for the tip.
Directly in Scriptable it works now.
But in the widget it says now.
Error on line … ReferenceError: Can`t find variable show_dayview

if(args.widgetParameter == null) {
  show_dayview = false
  show_overview = true
} else {
  const params = JSON.parse(args.widgetParameter);
  const show_overview = params.view ? params.view === "overview" : true;
  const show_dayview = params.view ? params.view === "dayview" : true;
}

What am I doing wrong?
Thanks

You seem to have some sort of mix between not defining show_dayview and show_overview in the first nested section of code, only using them, and then defining them as constants in the second nested section.

I would assume that you would want to reference them later outside of the nested sections and might want to simplify it down to something like this instead which sets up some variables and defaults before then overriding them if the data is available to do so.

// Define some variables with default values
let show_dayview = false;
let show_overview = true;

// Override the values of the defined variables if we have widget parameters to use
if(args.widgetParameter != null)
{
	const params = JSON.parse(args.widgetParameter);
	show_overview = params.view ? params.view === "overview" : true;
	show_dayview = params.view ? params.view === "dayview" : true;
}

Thanks. Now it works. :grinning: