# Javascript column help: Recurring classes

**URL:** https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334
**Category:** Ask for Help
**Created:** [March 1, 2024, 4:16pm UTC](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334 "2024-03-01T16:16:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![teshannon](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@teshannon](https://community.glideapps.com/u/teshannon)
#### Post date: [March 1, 2024, 4:16pm UTC](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334/1 "2024-03-01T16:16:51Z")

</div>

Hello, I am trying to setup a scheduling page where when a start date, recurrence pattern (1 for every day, 7 for weekly), and number of sessions (i.e 3) is provided, the remaining two dates are returned as an array.

In the data table, I have the following

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/4/b4b87499aafe1421a1e5962664ba8aba5c26f57b.png)

I then want to use the Javascript column, and this is the setup:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/0/c/0c21229e4daf87077ec2377e5803fab3029e845e.png)

The code (mind you, I am a total n00b) is here:

```auto
function calculateSchedule() {
    const startDate = new Date(p1);
    const recurrenceDays = parseInt(p2, 10);
    const numSessions = parseInt(p3, 10);
    let schedule = [];

    for (let i = 1; i < numSessions; i++) {
        let nextSessionDate = new Date(startDate.getTime() + recurrenceDays * 86400000 * i);
        schedule.push(nextSessionDate.toISOString());
    }

    return schedule;
}

const output = calculateSchedule();
output;

```

Glide Docs has info on the experimental column but nothing for the javascript column. In testing, I noticed console.log does not provide an output in the javascript column (duh); but it makes me think if there are other limitations within the javascript column? (Besides limited parameters.)

Any help would be greatly appreciated!

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [March 1, 2024, 4:20pm UTC](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334/2 "2024-03-01T16:20:49Z")

</div>

A few things.

- You are not passing your parameters as p1, p2, or p3, so your parameters aren’t being used in your code.
- You are not calling the function in your code, so it’s not even going to run.
- You can’t return arrays from a javascript column. You will have to convert it to a comma delimited string first, return the string, then use a Split Text column to convert it to an array.

For starters, add a function call like this outside of the function.  
`return generateSessionSchedule(p1, p2, p3);`

This will solve the first two points above.

---

<div class="post-metadata">

### Author: ![teshannon](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@teshannon](https://community.glideapps.com/u/teshannon)
#### Post date: [March 1, 2024, 4:27pm UTC](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334/3 "2024-03-01T16:27:41Z")

</div>

Jeff, thank you for the time, and I am a partial idiot, I pasted the wrong code.

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [March 1, 2024, 4:30pm UTC](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334/4 "2024-03-01T16:30:25Z")

</div>

OK, you still need a return on ‘output’, but you don’t even need to define an output variable. Just do a return on the function call.

You still need to convert your array to a string.  
Replace this:  
`return schedule;`  
With this  
`return schedule.join(',');`

---

<div class="post-metadata">

### Author: ![teshannon](https://avatars.discourse-cdn.com/v4/letter/t/d26b3c/32.png) [@teshannon](https://community.glideapps.com/u/teshannon)
#### Post date: [March 1, 2024, 4:44pm UTC](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334/6 "2024-03-01T16:44:50Z")

</div>

Lovely! Absolutely lovely! Thank you for your time.

The working code:

```auto
function calculateSchedule() {
    const startDate = new Date(p1);
    const recurrenceDays = parseInt(p2, 10);
    const numSessions = parseInt(p3, 10);
    let schedule = [];

    for (let i = 0; i < numSessions; i++) {
        let nextSessionDate = new Date(startDate.getTime() + recurrenceDays * 86400000 * i);
        schedule.push(nextSessionDate.toISOString());
    }

  return schedule.join(',');
}

return calculateSchedule();
output;

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/a/6a2d1395906e3e03f236a6bbda30df3b9a29001e.png)

---

<div class="post-metadata">

### Author: ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)
#### Post date: [March 1, 2024, 4:52pm UTC](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334/7 "2024-03-01T16:52:55Z")

</div>

Looks good!

You can get rid of `output;`. It’s not serving a purpose and is probably causing an unseen error because its an undefined variable.

 ![Screenshot_20240301-105105](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/a/1a7201320ea9a09e3378737b1c3bdcb5f2bbc84d.png)

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)
#### Post date: [March 8, 2024, 4:53pm UTC](https://community.glideapps.com/t/javascript-column-help-recurring-classes/71334/8 "2024-03-08T16:53:23Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
