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

Question

Question

Javascript to change text color when order number changes?

asked on February 5, 2020

Can JavaScript be used to change text color for rows in a table when the Order Number changes?  If you've done this successfully, could you share your code?

0 0

Replies

replied on February 6, 2020

Or can Workflow be set to do it after hitting the submit button?

0 0
replied on February 6, 2020

Hi Connie, can you share more about your process and what you're trying to do? It sounds like you want the color of the text to change whenever the number changes?

Just a quick note: you won't be able to save it with that color to the repository after it makes the changes on the form. The way that Forms works, you enter information that get stored as variables in a "variable pool" that's separate from the individual form submission. During the save to repository activity, Forms grabs the variables and plugs them into a brand new copy of the form - so anything that isn't stored specifically as a variable can't be saved to the repository, even if saving is the step right after submitting.

0 0
replied on February 6, 2020 Show version history

Hi Brian!  

This is a report on a Shelterbelt application process.  The report outlines all the applicants and their orders and will go to our Accounts Receivable clerk for invoicing.  I cannot get the collection-table to populate from the lookup in a way that separates the applicants visually.  They just show up as row after row of lines in the table.  So, I thought maybe I could get the table to change color of the text every time the applicant changes (which is the Order ID # since that is the Instance ID number).  At least that way, the AR clerk could easily see which rows to enter for any one applicant.  I want to make it very difficult for her to miss a line.

0 0
replied on February 6, 2020 Show version history

I have been googling this and only finding options to do alternate color changes and by copying code that I found the results only affected the lines between rows so far.

Unfortunately, while doing this testing, I discovered that even if I could get the form to display the row lines with alternating colors, the actual report that gets sent in an email does not reflect that color coding.  So, this is a second challenge that I have.

I guess, a way around this would be to send the report to the AR clerk and have an additional column for her to check off as she does the invoicing.  She could then Submit when done and the report gets saved (without the color coding, which wouldn't matter at that point).

0 0
replied on February 6, 2020

Actually, Brian, I removed the Collection field and changed this to just a table.  So my reference to a collection above might cause confusion when comparing notes.  

0 0
replied on February 6, 2020 Show version history

Hi Connie

You had me noodling this, and I came up with the following. As I'm not a JS programmer, this is done using a combination of a Formula in the Table and a JS script that changes the Row Color based on the value of the field created in my formula. The Color change is based on the Order Number

0 0
replied on February 6, 2020

Hi Steve!  Ya, I did find some JS that allowed for alternating rows with color, but for some reason it targeted the lines between the rows instead of the text.  Can you share your JS?  It doesn't actually meet my goal of changing when the Order# changes, but I'm still interested in this.

0 0
replied on February 6, 2020

It would be nice if the color change could be upon a variable change.  "If (new row number does not match previous row number), then...

0 0
replied on February 6, 2020 Show version history

Hi Connie, It just happens to be that the example I had where the Order Number has two lines items, It is actually changing on the Order Number Change

I'm now noodling if I could have the Gray bar behind Each Section, alternating, as opposed to just the change line

0 0
replied on February 7, 2020

In your Table, Add two new Fields (ROWID and COLOR) as Single Line Fields.

You can hide these with Fields Rules once you have tested

In the ROWID Field, add this formula to the field  =ROW()

In the Color Field, add this formula

=IF(INDEX(OrderTable.ROWID,ROW())="1","Grey",IF((INDEX(OrderTable.OrderNo,SUB(ROW(),1)))=(INDEX(OrderTable.OrderNo,ROW())),"White","Grey"))

You will need to update the table field names with your table variable

In the CSS Class of the Color Field, enter ColorSelect

In the CSS Class for the Table, enter MyTable

Enter the Following CSS code into the CSS pane

tr.RedRow {color:#f00;}
tr.RedRow input, tr.RedRow select {color:#f00;}

Enter the Following Javascript code into the Javascript pane

$(document).ready( function() {

$('.MyTable').on('change','.ColorSelect input', function() {
    if ($(this).val() == "Grey"){
        $(this).closest("tr").addClass("RedRow").css("background-color", "#cccccc");
    }else{
        $(this).closest("tr").RemoveClass("RedRow").css("background-color", "#ffffff");
    }
});
      
});
 

As you stated, this would likely work best if this task was sent to the AP, and had a Checkbox where they could mark they were completed. Another option would be to take the table data and write it to a CSV and email that, but that's a whole different animal.

1 0
replied on February 7, 2020 Show version history

Following your instructions, I now have the table changing the text color to red on the first line of a new Order ID#.  This is great!  Definitely an improvement.  If you figure out how to get it to change ALL the lines of one ID number, let me know as that would definitely be easier for the person invoicing the items on these lines, but this is still a great achievement!  

Thanks!

0 0
replied on February 7, 2020

QUESTION!  Why did the color coding not move on to the next process?

  • First User Task - Review Orders then submit to Accounts Receivable Clerk
  • 2nd User Task - AR Clerk opens form to complete invoicing as per list showing in form.

 

The color coding was working on 1st User Task viewing, but when it is sent to AP Clerk, the color coding isn't showing up.  ?

0 0
replied on February 7, 2020

It is likely because on the first form, the Lookup populated the Form, which triggered the change action in JS.

On the second form, the values are already there and don't change so the JS didn't trigger. I'll have to make a change to the code to account for both scenarios.

0 0
replied on February 8, 2020

Hi Connie, switch the JS I gave you previously with this code below, and I believe it should get you the result you want.

$(document).ready(function () { 
     
   rowcolorchange(); 
     
   $('.MyTable').on('change','.ColorSelect input', rowcolorchange); 
     
   function rowcolorchange() { 
     $('.MyTable tbody tr').each(function () { 
       $(this).find('.ColorSelect input').each(function () { 
         if ($(this).val() == "Grey"){ 
           $(this).closest("tr").addClass("RedRow").css("background-color", "lightGrey"); 
         }else{ 
           $(this).closest("tr").removeClass("RedRow").css("background-color", "White"); 
         } 
       }); 
 
     }); 
   } 
     
 }); 
 

0 0
replied on February 10, 2020

Hmm, after removing the previous JS and pasting in this JS, now the table is back to all the text (on all the lines) are back to grey.  No color changes anywhere.

0 0
replied on February 20, 2020

Hi Connie, was away to EMPOWER conference. Any further luck with this?

0 0
replied on February 24, 2020

No.  I was away all last week as well, but nothing has changed from what was posted above.

0 0
replied on February 25, 2020

I'm not sure at this point as the code is working fine here on my system

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

Sign in to reply to this post.