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

Question

Question

How to cast a multi-value Token/Retrieved Field to a List, and how to save it

asked on February 27, 2015 Show version history

I'm using workflow 9.1 to generate a .csv report from repository metadata.

I was trying to cast a multi-value retrieved field("MyField_All") to a List<string>, then add the retrieved value to another multi value string token("MyToken").

I was doing something like this:

List<string> list = this.GetTokenValue("MyField_All") as List<string>;
List<string> biggerlist = this.GetTokenValue("MyToken") as List<string>;

foreach(string item in list){
    biggerlist.add(item);
}

this.SetTokenValue("MyToken", biggerlist);

but seems a null value is saved into "MyToken" and seems I can't get the value out of "MyField_All".

What is the correct way of using a multi-value token/retrieved field like a list or array?

 

BTW, I'm currently using single-value token to store the result and use workflow "For Each Value" to iterate through the field. Which is just a walk around. Since string has a 2^31 length limitation, I can't just use one string to save all the data.

0 0

Answer

APPROVED ANSWER SELECTED ANSWER
replied on February 27, 2015 Show version history

Licheng, multi-value tokens are of type List<object> so you cannot cast it to List<string>. However, try casting your token to List<object> and then calling ToString() on the individual objects.

 

That said, I think Miruna's suggestion is better, as we have out-of-the-box functionality to do this without needing scripts, via the Assign Token Values and For Each Value activities:

1) Using For Each Value, go thru each item of "MyField_All"

2) For each of these values, use Assign Token Values to Append to the original MyToken (assuming it's a multi-value token). Note that when you append, you can easily do something like what you do in your script: 

0 0
replied on February 27, 2015

That would work. Thanks for the reply.

0 0

Replies

replied on February 27, 2015

Why not just use the "Modify" option in Assign Token Values to append "MyField_All" to "MyToken"?

0 0
replied on February 27, 2015 Show version history

Thanks for the reply. I will have to modify every string:


List<string> list = this.GetTokenValue("MyField_All") as List<string>;
List<string> biggerlist = this.GetTokenValue("MyToken") as List<string>;

foreach(string item in list){
    biggerlist.add(item+"Some Other Value");
}

this.SetTokenValue("MyToken", biggerlist);
 
0 0
replied on September 26, 2016

Hi Miruna - Here's the whole section:

 


        'Assign the document to the importer
        Try
            LF_Document = LFDB.GetEntryByID(lDocID)
            Importer.Document = LF_Document
            ' Locks the object for modification.
            LF_Document.LockObject(Lock_Type.LOCK_TYPE_WRITE)

            'Test the first page
            'Alternative
            'If bDocIsImage = True Then
            'Since we have already tested this.

            If Importer.IsAnImageFile(sDocumentFile) Then
                Importer.ImportImagesFromFile(sDocumentFile)
            Else
                Importer.ImportElectronicFile(sDocumentFile)
            End If

            'Clean Up and Return a Status
            Importer = Nothing
            LF_Document.Dispose()
            Return True

        Catch Ex As Exception
            sMessage = "Error in AddPagetoLFDocument for " & sDocumentFile & _
                                     " " & (Err.Description)
            WriteLog.WriteMessage(Now & " " & sMessage)
            AddPageToLFDocument = False
            Err.Clear()
            LF_Document.Dispose()
            Return False
        End Try

 

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

Sign in to reply to this post.