Skip to main content
Community site session details

Community site session details

Session Id : Yfns3S/IBxhcX+ACVaR8PZ
Power Automate - Power Automate Desktop
Unanswered

Getting syntax error or invalid value while running Run python script action in desktop flows

Like (0) ShareShare
ReportReport
Posted on 17 Oct 2023 20:03:04 by 2

this is the script I am running 

import datetime

# Get the current date
current_date = datetime.datetime.now()

# Initialize a counter
counter = 0

# Define the number of iterations
total_iterations = 730 # for 2 years

while counter < total_iterations:
# Calculate Date2 as Date1 - 15 days
date2 = current_date - datetime.timedelta(days=15)

# Print Date1 and Date2
print("Date1:", current_date.strftime("%Y-%m-%d"))
print("Date2:", date2.strftime("%Y-%m-%d"))

# Update Date1 for the next iteration
current_date = date2 - datetime.timedelta(days=1)

# Increment the counter
counter += 1

I have provide correct alligment to the script. Can someone help regarding this.

Categories:
  • Srinivas Kadamati Profile Picture
    3,150 Super User 2025 Season 1 on 18 Oct 2023 at 06:56:53
    Re: Getting syntax error or invalid value while running Run python script action in desktop flows

    Hi @Abhisht 

     

    Just set the indentation as below

     

    import datetime
    
    # Get the current date
    current_date = datetime.datetime.now()
    
    # Initialize a counter
    counter = 0
    
    # Define the number of iterations
    total_iterations = 730 # for 2 years
    
    while counter < total_iterations:
     # Calculate Date2 as Date1 - 15 days
     date2 = current_date - datetime.timedelta(days=15)
    
     # Print Date1 and Date2
     print "Date1:", current_date.strftime("%%Y-%%m-%%d")
     print "Date2:", date2.strftime("%%Y-%%m-%%d")
    
     # Update Date1 for the next iteration
     current_date = date2 - datetime.timedelta(days=1)
    
     # Increment the counter
     counter += 1
    

     

    Try as above and you are fine to get the results

     

    Srini84_0-1697612179845.png

     

    If you find this reply helpful, please consider giving it a LIKE AND

    If this reply answers your question or solves your issue, please ACCEPT AS SOLUTION

     

    Thanks,

    Srini

     

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on 18 Oct 2023 at 06:07:09
    Re: Getting syntax error or invalid value while running Run python script action in desktop flows

    Can you share a screenshot of your flow?

  • Abhisht Profile Picture
    2 on 18 Oct 2023 at 04:14:17
    Re: Getting syntax error or invalid value while running Run python script action in desktop flows

    its working but its showing empty in the display message 

  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on 18 Oct 2023 at 03:15:36
    Re: Getting syntax error or invalid value while running Run python script action in desktop flows

    The syntax error is because of the percentage symbols. These are reserved by PAD for variable notation. To pass a literal % to the script, you need to escape it with another %. Try this:

    print("Date1:", current_date.strftime("%%Y-%%m-%%d"))
    print("Date2:", date2.strftime("%%Y-%%m-%%d"))

     

    Please note, however, that PAD can only return a single value from a Python script. When you have several print statements, you will not get the actual 730 x 2 strings printed out. If you want that, you should in fact append your values to a single string inside the loop and then use a single print statement at the end of the script.

    -------------------------------------------------------------------------
    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 497 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 436 Super User 2025 Season 1

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 244 Super User 2025 Season 1

Loading complete