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

Question

Posted to Laserfiche Lounge

Trouble accessing multivalue token from SDK script

asked on July 7, 2016

I've researched this on the site and gathered what I have here but still cannot seem to grab more than a single value from a multivalue token.  In the workflow, I have a token setup with the box checked to accept multiple values, and I use the suggested  GetTokenAsMultiValue statement, and then iterate through the list it is applied to.  One value, every time.  This is what I have in the script:

 

namespace WorkflowActivity.Scripting.SDKScript
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using Laserfiche.RepositoryAccess;
    using System.IO;
    using System.Collections;
    using Laserfiche.RepositoryAccess.Common;
    using System.Linq;


    public class Script1 : RAScriptClass91
    {

        protected override void Execute()
        {
            StreamWriter csvWriter = new StreamWriter("C:\\Program Files\\Laserfiche\\Laserfiche Workflow 9\\MaryPoppinsDumbHead.csv");
            string headerRow;
            string dataRow;
            StringBuilder csvData = new StringBuilder();
            List<string> rowsList = new List<string>();

            headerRow = "Company Name, Renewal Date, Notice Date";
            csvData.AppendLine(headerRow);
            csvWriter.WriteLine(headerRow);

            dataRow = "";

            string jackoe = TokenReplace("%(DataResultsCounter)");
            int jacko = Convert.ToInt32(jackoe);

            List<object> values = this.WorkflowApi.GetTokenAsMultiValue("newName2");

            foreach (string result in values)
                {
                rowsList.Add(result);
                dataRow = result;
                csvData.AppendLine(dataRow);
                csvWriter.WriteLine(dataRow);
            }

            csvWriter.Flush();
            csvWriter.Close();
            csvData.Clear();

        }
    }
}
 

 

Can anyone help with this please?

0 0

Answer

SELECTED ANSWER
replied on July 11, 2016

Did you check that the token has multiple values going into and coming out of the conditional sequence?

Are you writing the formatting by hand? I'd have expected "//." in the Split function from the token editor, not just "/.". And the delimiter seems to be a space not a newline character, which would make the resulting token a single-value token.

0 0

Replies

replied on July 11, 2016

Anyone?

0 0
replied on July 11, 2016

Rick,

When I run your script it seems to work as anticipated.  (Workflow 9.2.0.167)

My multi-value token;

The resulting CSV;

0 0
replied on July 11, 2016

A second test with comma separated values also works;

0 0
replied on July 11, 2016

Is this when the workflow runs or are you providing values when manually running the script from the Script Editor? Where does the multi-value token get its values?

0 0
replied on July 11, 2016

If I put those values in the token editor manually it works for me too.  The problem is, they are being loaded dynamically through workflow, and I am having trouble but not sure whether it's the setup of the multi-value token or in accessing it through the SDK.  The newName2 variable is setup like this in workflow:

 

The reason for the CurrentEntryId tacked on after it is because it is a report generated in LF Forms, and without doing that it doesn't allow me to have duplicate values in a dropdown that I am using to populate tables on lookups.  The report was wanted in Forms for mobility, but they also want an Excel version now which is why I am trying to do this.  The multiple values show up in the logs after each run as wanted, but the script never gets more than one value, unless I enter them myself in the token editor like you have done, Cliff.  I've also tried using the SetMultiValueToken command I saw somewhere, but for some reason that isn't available in my resources.

0 0
replied on July 11, 2016 Show version history

Add a Track Tokens before going into the script to double-check. But your token looks single-value to me.

%(ForEachEntry2_CurrentEntry_ID#@Split(/.)@##[]#) would be blank a single value since there are no "/." in the entry IDs or newlines to split on.

%(newName2#[]##<.{1,37}>#) would split newName2 into individual lines then match at most 37 characters on the first line.

0 0
replied on July 11, 2016

I had my track tokens activity inside the for each entry loop, so that's why I was getting all the values in the log...you're right, when I track tokens just before the script, outside of the for each loop, I am only getting one.  I can't put the script activity inside the loop, so how do I access the multiple values later outside the loop from the script?  My GetTokenAsMultivalue doesn't seem to work in that case.  I took the currentEntryID off the end of the name and just left the name, and that didn't work either.  I also took off the delimiter for characters {1,37}.

0 0
replied on July 11, 2016

Where is newName2 coming from?

0 0
replied on July 11, 2016

I am grabbing a field from a template on a document (counterparty), naming it newName2, and then if it passes a date range condition it goes through a conditional sequence where I have the above token modifying it.  I only want to keep track of the ones in this conditional sequence.  There are other variables that will be in the rows, but I am just using this one variable until I figure out how to get the multiple values. 

0 0
replied on July 11, 2016

The original token declaration:

 

0 0
SELECTED ANSWER
replied on July 11, 2016

Did you check that the token has multiple values going into and coming out of the conditional sequence?

Are you writing the formatting by hand? I'd have expected "//." in the Split function from the token editor, not just "/.". And the delimiter seems to be a space not a newline character, which would make the resulting token a single-value token.

0 0
replied on July 12, 2016

No, didn't set anything by hand, I'm not sure why it does that but it throws extra slashes in there quite often on me for some reason.  I am trying adding a delimiter through a script before the token creation, and using that as a breakpoint for the values.  I found an old post where you had mentioned that, maybe that will solve it for me.

0 0
replied on July 12, 2016

We are going to be upgrading to version 10.1 from 9.2 in the next week or two.  Will this be made any easier in the new version?

0 0
replied on July 12, 2016

There's no difference in the behavior between 9.2 and 10.1. It's probably best that you have your reseller open a case with Tech Support and attach a sample (simplified if possible) workflow that reproduces the behavior.

0 0
replied on July 12, 2016

Thanks Miruna...it seems to be an issue with the modifications I'm making to the token.  If I just accept the token and maybe use an expression, it is working.  However, as soon as I add something to it to make it unique (such as the entryID on the end for the Forms table), it stops working.  Maybe because I have two variables there, the newName2 variable I am modifying and the EntryID??  Not sure.  At any rate, what I can do is use the stripped down version before the script so I can write to Excel as a .csv file, and then add the additional info before saving it to the database so I can then use it as a lookup for the final form.  I appreciate all your help.

0 0
replied on July 12, 2016

Didn't work.  Nothing seems to grab anymore than one value for me.  This is very frustrating, because if I create an empty token in a new workflow before a for each loop and then modify it within the loop everything works, which is what I am trying to do here, but for some reason it doesn't. 

You are not allowed to follow up in this post.

Sign in to reply to this post.