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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Run VB Script variable...
Power Automate
Suggested Answer

Run VB Script variable assignment

(1) ShareShare
ReportReport
Posted on by 6
Hi All,
 
I'm trying pass the power automated output variable %AttributeValue% with a text of "IN998877 - A-BB-CCC-DDEERFFFFRE FR" to a run VB Script to extract the output of "IN998877", but it seems neither var %AttributeValue% is not picking the value or not knowing how to be assigned with. so please help to resolve it.

Dim inputText, startPos, endPos, extractedText

inputText = %AttributeValue%

'inputText = "IN998877 - A-BB-CCC-DDEERFFFFRE FR"

startPos = InStr(inputText, "IN")

endPos = InStr(inputText, " -") - 1



If startPos > 0 And endPos > 0 Then

    extractedText = Mid(inputText, startPos, endPos - startPos + 1)

    WScript.Echo extractedText

Else

    WScript.Echo "Text not found"

End If
I have the same question (0)
  • Suggested answer
    eetuRobo Profile Picture
    4,579 Super User 2026 Season 1 on at
    Add double quotes around the variable:

    Dim inputText, startPos, endPos, extractedText

    inputText = "%AttributeValue%"

    'inputText = "IN998877 - A-BB-CCC-DDEERFFFFRE FR"

    startPos = InStr(inputText, "IN")

    endPos = InStr(inputText, " -") - 1



    If startPos > 0 And endPos > 0 Then

        extractedText = Mid(inputText, startPos, endPos - startPos + 1)

        WScript.Echo extractedText

    Else

        WScript.Echo "Text not found"

    End If

    Then output was: IN998877


    Always good practice to add ScriptError output variable on Script actions:


    ScriptError value:


    That says the problem is at line 3

  • CU13110258-0 Profile Picture
    6 on at
     
    thanks for the suggestion and i have tried the same mentioned above with double quotes (" ") and enabling the Script error however still i'm getting "text not found" msg and in the flow it shows "its error into Script Error" and fail after 50 seconds but not showing in variable and in display msg while testing to see the error output.
     
  • Suggested answer
    eetuRobo Profile Picture
    4,579 Super User 2026 Season 1 on at
    Then your variables seems to work so its more about the value inside the variable or the extraction logic. Can you show a screenshot of the AttributeValue variable on PAD? Make sure in your VBScript only the %AttributeValue% has double quotes around it and not VBScript own inputText variables. So only add doublequotes around the %AttributeValue% in your original code you posted.

    You can test that the variable assignment actually works with adding to the else echo: WScript.Echo "Text not found from " + InputText 

    Then you would get the variable value in the "Text not found" result:
    (I intentionally changed the variable values starting I -> i to get the not found condition)


    How it works with your code when I have the 
    inputText = "%AttributeValue%"


    If the ScriptError is empty then the VBScript didn't go in to error so the condition just wasn't met. 

    https://learn.microsoft.com/en-us/power-automate/guidance/rpa-sap-playbook/adding-variables-to-vbscript

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 252 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard