You are viewing limited content. For full access, please sign in.

Question

Question

Workflow SDK setMultiValueToken syntax / documentation location

asked on March 24, 2022

Client has a data hygiene issue, involving multi-valued tokens.

To fix this issue, using SDK scripts in workflow will be the best way forward.

Dim mainToken As List(Of Object) = Me.GetTokenValue("mainToken")
Dim otherToken As List(Of Object) = Me.GetTokenValue("otherToken")

dim maxCt as integer = UnmainToken.count()

if otherToken.count() < MaxCt then
for idx = otherToken.count() - 1 to (maxCt - 1)
otherToken(idx) = 0
next
endif

setMultiValueToken("otherToken", otherToken, false)

but for the "set" step - an error gets thrown :

Unable to cast object of type 'System.String' to type 'System.Collections.Generic.List`1[System.Object]'.

1. What is proper syntax to return a multivalued token to the calling workflow?
(We are fine with either VB or C#, don't care)

2. where are these function calls documented? The SDK / .NET SDK / Online docs are not helpful.

Thanks!

0 0

Replies

replied on March 24, 2022 Show version history

Looking at your script - it looks like you are trying to clear out a multi-value token.  I don't really understand why it is necessary to do that via a Script instead of just using an "Assign Token Values" activity to clear the token, but assuming you have a compeling reason wink let's review your script.

When I create a workflow with two multi-value tokens, mainToken and otherToken, and pre-populate mainToken with some numbers (1, 2, 3, 4, and 5) and set it as an integer type token, and pre-populate otherToken with some numbers (1, 2, and 3) and set it as an integer type token, then add your script as you have listed it, I get the following errors:

So I tweak it as follows: change lines 4 to reference mainToken instead of unmainToken, add line 5 to declare the idx variable, and edit line 11 to include a space between end and if - script now looks like this: 

            Dim mainToken As List(Of Object) = Me.GetTokenValue("mainToken")
            Dim otherToken As List(Of Object) = Me.GetTokenValue("otherToken")

            dim maxCt as integer = mainToken.count()
            dim idx as integer = 0

            if otherToken.count() < MaxCt then
                for idx = otherToken.count() - 1 to (maxCt - 1)
                    otherToken(idx) = 0
                next
            end if

            SetMultiValueToken("otherToken", otherToken, false)

side note - using the "code" tags like this when posting makes it easier to read your code.

With those changes I don't get any errors and can publish, but when running the workflow, I get a message that the index was out of range.

In my example, the otherToken had a count of 3 and the mainToken had a count of 5, that for next loop is trying to run otherToken index 2 to 4 of the otherToken, but there is only 3 in there, so that's our index error.

I don't think I can get this code to work, because it's only running that loop if the otherToken count is less than the mainToken count, and then it's trying to loop through otherToken to the length of mainToken - which is always going to cause an index error, since otherToken had to be shorter to even get through the if statement and to the loop.

It would help if you provided a little more explanation regarding what the various tokens are used for, the situation if which you are trying to update them in the script, etc.

0 0
replied on March 24, 2022 Show version history

By the way, you do have the syntax correct for SetMultiValueToken.  It's just not getting that far through the script in order to actually update them.  When I test with otherToken as an integer type token prior to the script, and is pre-populated with 1, 2, and 3, and then run this script:

            Dim otherToken As List(Of Object) = Me.GetTokenValue("otherToken")
            otherToken(0) = 99
            otherToken(2) = -1
            SetMultiValueToken("otherToken", otherToken, false)

I end up with the token looking like this:

Exactly as expected: 99 and -1 from the script and 2 from the original creation of the token prior to the script.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.