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

Question

Question

Another Lookup Overwrite Question

asked on June 19, 2020

I know this has been a question going back years on Answers and it still does not seem to work and figure I would ask for suggestions.  We continually run into this and are not able to provide our clients with solutions

I have a table that has a lookup rule tied to cost center.  Its just a fill rule with a list of available cost centers from SQL.

What I would like is that if Fund Category = Employer simply default the Cost Center to 1000.  No matter which of the following I do, the result is that if the 1000 goes into Cost Center automatically, all the other lookup choices are removed.

1.  Use formula on cost center - IF (fundsource="Employer","1000","").  I removed the row index stuff to simply it.  This works but again if they need to change it the drop down is gone or screws up other rows in the table.

2.  Use a lookup rule to populate the cost center drop down (like above).  Have an entire other SQL table that simply has one row with employer and 1000.  Hook that lookup rule to the field as well.  This works but I loose the other drop downs.

3.  Change cost center to a list field.  Put all cost centers in the list and check the "append to lookup choice".  The defaults but again loose other lookup choices.

We continually run into this and users of the process are a little surprised that Laserfiche cant do this action at least through standard setups.

Is there javascript out there that could accomplish this?

 

0 0

Answer

SELECTED ANSWER
replied on June 19, 2020 Show version history

The problem you're having is that you're essentially creating conflicting lookups by trying to make the lookup responsible for the default value.

The suggestions will go away when a value is entered into the field as a side effect of the filtering (i.e., when you start typing it narrows the list, so the options will all be gone if you enter an exact match or nothing matches the field value). If you want the other options to always be listed it is better to use a dropdown.

As for defaulting, you could set a change event trigger on the Fund Category field, but you have to do it a specific way since this is a table.

First, add a CSS class to your table; this will be used to monitor change events for the entire table and filter out the ones you want to react to, which is really the best option for tables with dynamic rows.

Next, add CSS classes to the two fields; the first will allow you to detect changes to the fund category, and the second will allow you to update the corresponding cost center to a default value.

$(document).ready(function(){
  // detect change events in the table
  // filtering applied to only react to fund category changes
  $('.myTable').on('change','.fundCategory :input',function(){
    // check the field value
    if($(this).val() == 'Employer'){
      // update cost center for the same row
      $(this).parents('tr').find('.costCenter :input').val('1000').change();
    }
  });
});

I used :input in the example because it is dynamic, meaning it will work regardless of whether you use single line fields or dropdowns.

1 0
replied on June 19, 2020

Yeah, I get why it doesnt work it would just be great if we could get Forms to recognize the items out of the box.  Thanks you for the example code I will give that a shot!

0 0

Replies

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

Sign in to reply to this post.