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

Question

Question

Individual Row Results

asked on September 27, 2016

I have a table in forms and I want to paste the results in an HTML Fields. But the table is only one column and one row. 

When I insert the variable into the html field, I would like the results to be separate instead I get the results separated by semicolons

0 0

Answer

SELECTED ANSWER
replied on September 28, 2016

Oh if that's all, you should be fine with using

<script>
$(document).ready(function() {
  var stuff = "{/dataset/Table/Column}".split("; ");
  $('#customContent').html(
    "Employee selected the following number " +
    stuff[1] +
    " for question 2.");
});
</script>

<div id="customContent"></div>

and this will display that sentence in the actual form.

If you meant you wish to retrieve that individual value in the Workflow, you can use an Assign Tokens activity and use the token calculator to specify the 2nd index (note that here, the indices are one-based so you would choose 2, not 1).

I feel partly responsible for your confusion, so trying to do my best to help work it out...

Workflow-Choose-Specific-Value.png
1 0

Replies

replied on September 27, 2016

Hi Chynna, could you please elaborate on the setup? I am guessing you mean you have a table in one form which is being used to populate a custom HTML element in a subsequent form in the process? When I do this with a table that has a single column and fixed number of rows (1) and a text field I only get the one value with no semicolons. Are you using a different field type, or have I misunderstood something else along the way?

0 0
replied on September 27, 2016

I have 5 rows...sorry. And the values are split by semi colons. Is there anyway to break that down, so I can create a report in Forms.

0 0
replied on September 27, 2016

Thanks for the clarification. The result from e.g. {/dataset/Table/Column} is a string with the values demarcated by semicolons. So for example if for my 5 rows I have the values 1, 2, 3, 4, and 5, the variable value will be the string "1; 2; 3; 4; 5".

So we can parse this with JavaScript. In the custom HTML element, in the HTML editor you can add:

<div id="customContent"></div>

This registers a <div> element that we can fill.

Now while we do eventually want to parse the data with JavaScript, we can't use the variable syntax in the custom JavaScript editor. So we'll add a script element in the custom HTML field itself:

<script>
$(document).ready(function() {
  var stuff = "{/dataset/Table/Column}".split("; ");
  $('#customContent').html(stuff.join(','));
});
</script>

<div id="customContent"></div>

Everything we'd normally put in the custom JavaScript area, we can put right in here. The above code will cause the custom HTML to show the string "1,2,3,4,5" from the previous example. See Example-1.png.

The .split("; ") method is the key here; it takes a string and returns an array of elements which were originally separated by the "; " substring. So each entry of this array are our table input values, in order, and can be accessed as such. For example:

<script>
$(document).ready(function() {
  var stuff = "{/dataset/Table/Column}".split("; ");
  $('#customContent').html(
    "The first item was " + stuff[0] +
    " and the second item was " + stuff [1] +
    ", followed by " + stuff[2] +
    " and " + stuff[3] +
    ", before finally ending with " + stuff[4] +
    ", the fifth and final item."
  );
});
</script>

<div id="customContent"></div>

Note that the indices of the array are zero-based, so the first element is index 0, the second is index 1, etc. See Example-2.png for the result.

And lastly you can even add HTML tags in this, for example:

<script>
$(document).ready(function() {
  var stuff = "{/dataset/Table/Column}".split("; ");
  $('#customContent').html(
    "The first item was <b>" + stuff[0] +
    " and bold</b> and the second item was <i>" + stuff [1] +
    " and italicized</i>, followed by <span style='color: red'>" + stuff[2] +
    " which was red</span> and <span style='color: blue'>" + stuff[3] +
    " which was blue</span>, before finally ending with <pre>" + stuff[4] +
    "</pre>This unformatted, fifth and final item, was displayed as if it was code."
  );
});
</script>

<div id="customContent"></div>

Which is a bit silly, in Example-3.png. You may be able to take this farther to meet your reporting needs.

Hope this helps!

Example-1.png
Example-2.png
Example-3.png
Example-1.png (8.23 KB)
Example-2.png (12.52 KB)
Example-3.png (18.61 KB)
0 0
replied on September 27, 2016

Gosh, I didn't think it would involve special scripting. This is what I am looking for though. 

0 0
replied on September 27, 2016

Unfortunately it does. This is all just because of how the variable value is displayed. Thinking about it further, some special handling may need to be required if the data actually contains semi-colons, as that would throw off the .split('; ') operation. It would depend on what kind of data exactly you'll be dealing with.

0 0
replied on September 27, 2016

So it might tamper my end workflow...HMMM. My workflow is way more important than the other report. The report I want to create would just be an HTML moving explanations in a cleaner look than the read only fields.

0 0
replied on September 27, 2016

Hi Chynna,

To clarify having semicolons in the field will affect how this custom script runs to make the report in the custom HTML element on the form; it won't affect how Workflow processes the field values. The attached image demonstrates that even with semicolons in one of these fields, when Workflow pulls the value using a "Retrieve Business Process Variables" activity, it correctly demarcates which values go to which fields, and can properly assign metadata to a multi-value field of a repository entry.

Custom HTML elements, it should be noted, are intended for display on a form; they are not "variables" which can be retrieved in this manner on a Workflow.

Is that relevant to your concern, or were you more worried about something else?

Semicolons-in-Table.png
0 0
replied on September 28, 2016

I think it was more something else. I was using the HTML to construct a report within a form but I wanted to use Column Variables within the HTML report. I don't want to retrieve the HTML field. In your picture, if I wanted to use row 2 in a HTML sentence because this is an important number. 

EX:

Employee selected the following number  4 for question 2. 

I just want to pull that one answer out not the whole sequence.

But I think I will just change my method/process, seems like I am causing more confusion for myself.

0 0
SELECTED ANSWER
replied on September 28, 2016

Oh if that's all, you should be fine with using

<script>
$(document).ready(function() {
  var stuff = "{/dataset/Table/Column}".split("; ");
  $('#customContent').html(
    "Employee selected the following number " +
    stuff[1] +
    " for question 2.");
});
</script>

<div id="customContent"></div>

and this will display that sentence in the actual form.

If you meant you wish to retrieve that individual value in the Workflow, you can use an Assign Tokens activity and use the token calculator to specify the 2nd index (note that here, the indices are one-based so you would choose 2, not 1).

I feel partly responsible for your confusion, so trying to do my best to help work it out...

Workflow-Choose-Specific-Value.png
1 0
replied on September 28, 2016

No you helped...I have confused myself more. I think I will avoid the scripting because I have 16 fields to possibly do this to and I feel sure I will never get it right.

laugh

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

Sign in to reply to this post.