Invoke Code 사용 방법 (How To Use Invoke Code)

Dim A As String = “SNP”
Dim B As String = “500”
Dim C As String = A & “_” & B

Invoke Code의 코드 부분에 위와 같은 코드를 작성하고
결과적으로 C값을 받아와서 이후 작업을 하려고 합니다.

  1. Invoke Code에 작성된 코드의 결과값을 해당 엑티비티 밖에서 받아서 사용 하려면 어떻게 해야 하나요?
  2. Invoke Code 밖에서 만들어진 특정 값을 Invoke Code의 내부에 넣어서 코드를 적용 시키고 싶습니다. 가령 Assign 등으로 Name = “Samsung” 이라는 값을 선언 하고 이 Assign으로 선언된 값을 Invoke Code의 내부에 넣어 .split 등 의 메소드를 적용 시키려면 어떻게 해야 하나요??

=================================================

English ver

I am writing code like the above inside the Invoke Code activity, and I want to use the resulting value (C) outside of that activity.

  1. How can I retrieve the result value from the code inside the Invoke Code activity and use it outside the activity?
  2. I also want to pass a value created outside of the Invoke Code activity into it.
    For example, if I declare a value using Assign like Name = "Samsung", how can I pass this value into the Invoke Code activity and apply methods like .Split inside the code?

Hello @692622,

You need to use the Arguments section of Invoke Code.
To send a value into Invoke Code, create an In argument.
To get a result back outside, create an Out argument.

Example in VB:

Arguments

  • in_A → In → String
  • in_B → In → String
  • out_C → Out → String

Code

out_C = in_A & "_" & in_B

Then map in_A = A , in_B = B , and out_C = C .

For an outside variable like Name = "Samsung" , pass it as an In argument:

Dim arr() As String = in_Name.Split(" "c)
out_FirstPart = arr(0)

That is the standard way to consume external values inside Invoke Code and return results back to the workflow.

Thanks,
Karthik

@692622

In Invoke Code activity, click Edit Argument as shown in below screenshot and create required in and out argument, click ok then Save.

then click Edit Code, here you can write your code and use the arguments created:

To pass values in and out of the Invoke Code activity, you must use the Arguments panel. Think of arguments as the “bridge” between your workflow variables and the code inside the activity.

Here is exactly how to set it up:

1. Define the Arguments (The Bridge)

In the Properties panel of your Invoke Code activity, click the three dots ... next to Arguments. Set them up like this:

Name (Inside Code) Direction Type Value (Outside Variable)
Name In String str_Name (Created via Assign)
ResultC Out String str_Result (Variable to hold the output)
  • In: Brings data from your workflow into the code.
  • Out: Sends data from your code back out to your workflow.

2. Write the Code

Inside the Edit Code window, you do not need to use Dim for any variable defined in the Arguments list. You can use them directly.

=========================================================
Code snippet:

’ 1. Using the “In” argument (Name) passed from outside
’ Example: Applying .Split to “Samsung”
Dim parts As String() = Name.Split("s"c)

’ 2. Your logic for SNP_500
Dim A As String = “SNP”
Dim B As String = “500”

’ 3. Assign the result to the “Out” argument, This value will now be available in your str_Result variable outside
ResultC = A & “_” & B

=========================================================

3. Key Rules for Success

  • No Redeclaring: Do not use Dim ResultC As String inside the code if you already defined ResultC in the Arguments list. If you do, the code will create a local variable and won’t send the value back out.
  • Argument Direction: If you want to modify a variable and send it back out (like changing “Samsung” to “SAMSUNG”), use the InOut direction.
  • Case Sensitivity: Ensure the names in your code match the names in the Arguments list exactly.

Guys, Invoke code is effectively legacy.

We have had coded workflows for years.
Just write this in a coded workflow for a proper coding experience and better handling, there is no need to suffer through invoke code now.

I followed the method you suggested, but the result is coming out as null.
Is there something I might have missed?
Or could there be another issue causing this?

// here is my logic

I’ve posted the method I tried in the comments.
It seems like it didn’t work properly in the end—could you please take a look?

As long as you don’t mind all the bugs that come with coded workflows.. sure.

That feels abit passive aggressive.
I don’t experience the bugs you talk of, tell me what bugs occur in situations like this that makes invoke code superior?