web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Using power automate d...
Power Automate
Answered

Using power automate desktop variables in VBScript

(1) ShareShare
ReportReport
Posted on by 25
Hello!
I'm trying to write a VB script that will use a variable initialized within a flow. My variable is a list of numeric elements (%List%). I want the script to check if a given value in the %List% is less than 0 and if so, to save its position as a result. If the next value meets the same condition, its position in the list is to be appended to the result after the decimal point. Unfortunately, I run into a problem - I can't use the %List% variable. Depending on the way I try to use it, I get compilation errors. An example of a script I tried to use:
 

Dim list
list = Split(%List%, ",")
Dim result
result = ""
For i = 0 To UBound(list)

    If CInt(list(i)) < 0 Then

        If result = "" Then

            result = i

        Else

            result = result & "," & i

        End If

    End If

Next

WScript.Echo result
 
I will be very grateful for any help!
Best regards!
Iza
I have the same question (0)
  • Verified answer
    NathanAlvares24 Profile Picture
    1,714 Moderator on at
     
    The List variable in PAD (Power Automate Desktop) is completely different than what an actual List used in scripting languages.
     
    See this example:
     
    Output of "Display message" action:
    As can be seen it is not like the list in scripting languages. A list in scripting languages usually has a ","(comma) as a delimiter.
     
    So you need this into one whole text. Use the "Join text" action to achieve this. See below:
     
     
    Output:
    As can be seen above, I get the list as one whole text and delimited by a comma.
     
    Then pass this variable to your script. I made some changes to the script, so use this one:
    ' Initialize the list with the actual Power Automate variable
    Dim list
    list = Split("%List%", ",") ' %List% should be a string like "1,2,-3,4,-5"
    
    ' Initialize the result variable
    Dim result
    result = ""
    
    ' Iterate through the list and check for negative values
    For i = 0 To UBound(list)
        If CInt(list(i)) < 0 Then
            If result = "" Then
                result = i
            Else
                result = result & "." & i
            End If
        End If
    Next
    
    ' Output the result
    WScript.Echo result
     
    Then finally your flow will look like this (just for reference):
     
    We have to use the "Trim text" action, since in PAD, the scripting languages give output as one extra line.
     
    Output:
     
    Flow (directly copy the code and paste onto your flow):
    Variables.CreateNewList List=> List
    Variables.AddItemToList Item: 1 List: List
    Variables.AddItemToList Item: 2 List: List
    Variables.AddItemToList Item: -3 List: List
    Variables.AddItemToList Item: 4 List: List
    Variables.AddItemToList Item: -5 List: List
    Text.JoinText.JoinWithCustomDelimiter List: List CustomDelimiter: $''',''' Result=> List
    @@copilotGeneratedAction: 'False'
    Scripting.RunVBScript.RunVBScript VBScriptCode: $'''\' Initialize the list with the actual Power Automate variable
    Dim list
    list = Split(\"%List%\", \",\") \' %List% should be a string like \"1,2,-3,4,-5\"
    
    \' Initialize the result variable
    Dim result
    result = \"\"
    
    \' Iterate through the list and check for negative values
    For i = 0 To UBound(list)
        If CInt(list(i)) < 0 Then
            If result = \"\" Then
                result = i
            Else
                result = result & \".\" & i
            End If
        End If
    Next
    
    \' Output the result
    WScript.Echo result
    ''' ScriptOutput=> VBScriptOutput ScriptError=> ScriptError
    Text.Trim Text: VBScriptOutput TrimOption: Text.TrimOption.Both TrimmedText=> VBScriptOutput
     
    I hope this helps.
     
    Regards,
    Nathan Alvares

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard