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 / 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,204 Super User 2025 Season 2 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,204 Super User 2025 Season 2 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

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 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard