Hello ,
I have one javascript code in which i want to pass dyanamic time (which is stored in list)in array,How can i pass this array values.
Below is my Javascript code.
$parameters.TimeoutId = 0;
$parameters.SetInterval = 0;
//var interval=0;
// Schedule specific task at n times every day
function scheduleTasks(times, task) {
const now = new Date();
times.forEach((time) => {
const [hours, minutes, seconds] = time.split(":").map(Number);
const scheduleTime = new Date();
scheduleTime.setHours(hours, minutes, seconds, 0);
// If the schedule time is in the past for today, schedule for tomorrow
if (scheduleTime < now) {
scheduleTime.setDate(scheduleTime.getDate() + 1);
}
const delay = scheduleTime - now;
// Schedule the task
setTimeout(() => {
task();
// Reschedule for the next day
setInterval(task, 24 * 60 * 60 * 1000);
}, delay);
});
// Example usage
const taskTimes = ["16:26:00", "16:29:00", "16:31:00"]; // Times in HH:mm:ss format
Here i want to pass dynamic values coming through list in outsystems in same format.
This hardcoded values works fine
const myTask = () => {
$actions.TriggerOfflineDataSync("gate-logs");
//$actions.TriggerOfflineDataSync()
alert("Task executed at", new Date().toLocaleTimeString());
};
scheduleTasks(taskTimes, myTask);
Yours help will be appreciated.
Thanks in advance
Hi,
Convert the List to JSON -
If you have a list of times like ["13:26:00", "13:29:00", "13:31:00"], you will create a string:
Assign the JSON string to a local variable called TaskTimesJSON.
Pass JSON to JavaScript -
var taskTimes = JSON.parse($parameters.TaskTimesJSON); // Parse the JSON string into an array
alert("Task executed at " + new Date().toLocaleTimeString());
// Schedule tasks using dynamic times
Thanks,
Vipin Yadav
I have added another screenshot for your references -
Hey thanks Vipin, for the reply
but i get another error msg .
Plz check the below screenshot.
Following same steps given by you
Thanks vipin for your valuable response but i achieved this with another way by using javscript.
var nestedJsonArray = JSON.parse($parameters.In1);
var namesArray = nestedJsonArray.map(item => item.SyncTime2.Time);
alert(namesArray);
$parameters.Out1 = namesArray;
-bind this output to output variable which object data type n passed this to my next javascript as input variable with same data type .
Ok thanks
i got this json output from outsystems after serialize but i want only time like ["16:26:00", "16:29:00", "16:31:00"];
[{"SyncTime2":{"Id":25,"Time":"17:27:00"}},{"SyncTime2":{"Id":26,"Time":"17:31:00"}}]
Hi @Bharat koshti,
You can create a structure with a single attribute, then assign a local variable to this structure in the form of a list. Set the 'Time' variable to "17:27:00", serialize it to JSON, and then pass the value to JavaScript.
The idea of using JSON is the more important part of this solution, how exactly you use it in your javascript is an implementation detail.
So I also marked the answer of @Vipin Yadav as solution.
Dorine