Database Insert from DMX Repeat

Hello,

I have a server action called save_billing that includes a repeat function to retrieve the number of days in the month from the table.

<form id="hoursBillingForm" is="dmx-serverconnect-form" action="/api/hoursBilling/save_billing" method="post" dmx-on:success="notifies.success('Form submitted successfully!')" dmx-on:error="notifies.danger('Error submitting form')">
    <!-- Form for entering hours billing -->
    <input type="hidden" id="tages" name="tages" value="query.month.monthDays().daysInMonth">
</form>

The issue I'm facing is that the repeat function only iterates once, and it seems like the rest of the code or the database insert is only processing a single entry. I’m not sure if I’ve missed something or if there’s an error in my approach.


Screenshot 2024-10-27 102436

Your form field is called “days”. But on the server side usage you have “tages” as name …

this was an auto translation error in the html the id is tages too

<input type="hidden" id="tages" name="tages" value="query.month.monthDays().daysInMonth">

You probably need to convert it to number first with the toNumber formatter so that you can loop so many times. Otherwise default form fields are all strings and it will loop for the length of the string so just once in your case

Sorry for that stupid question but where? In the Server Action or in the HTML Code?

It's in the Server Action :slight_smile:

image
Like this? Because it wont work

What value does this return in your server action?

<input type="hidden" id="tages" name="tages" value="query.month.monthDays().daysInMonth">

and what is this expression exactly? query.month.monthDays().daysInMonth

I have this
URL/activesession/hours?month=october2024

and query.month.monthDays().daysInMonth just returns the number of days like for example 31 for october

If you are referring to the code i provided a few weeks back:

Your expression is not correct.
It should be: query.month.monthDays() and not query.month.monthDays().daysInMonth

check my answer in the linked topic again.

dmx.Formatter('string', 'monthDays', function(val) {
    // Extrahiere den Monat und das Jahr aus der URL
    const date = moment(val, 'MMMMYYYY');  // 'val' ist z.B. 'may2024'
    
    // Extrahiere den Monat und das Jahr
    const month = date.format('MMMM');  // Gibt den vollständigen Monatsnamen zurück, z.B. 'May'
    const year = date.format('YYYY');   // Gibt das Jahr zurĂĽck, z.B. '2024'
    
    // Berechne die Anzahl der Tage im Monat
    const daysInMonth = date.daysInMonth();

    // Konvertiere den Monatsnamen in eine Zahl (1-12)
    const monthNumber = date.format('MM');  // 'MM' gibt den Monatswert als Zahl zurĂĽck, z.B. '05' fĂĽr May
    
    
    // Gib ein Objekt mit Monat, Jahr und Anzahl der Tage zurĂĽck
    return {
        month: month,
        monthNumber: monthNumber,
        year: year,
        daysInMonth: daysInMonth
    };
    
  });

this is the script i use atm

Please create a setvalue step in your server action, give it a name, assign the $_POST.tages variable value to it and enable output.
Check the response in the dev tools > network tab > XHR to see what the setvalue step returns. Post a screenshot here.

server-connect:output Days: '31'
server-connect:app Executing action step repeat
server-connect:app options:
repeat: '{{Days}}'

so am i missing a step or should it work like this?

sorry i am not sure i understand what is server-connect:app in your explanation.
Can you please post a screenshot of the output you see for the setvalue step in the network > xhr tab and also how is your repeat configured.

I'm soo damn sorry for my stupid answers.. I really need to sleep..
It worked i'm so thankful for all your help

1 Like