Picklist Value Rendering Based on Text Field Value

edited July 13, 2017 in Questions
I imagine someone has asked this before, but I can't seem to find it after looking through a few dozen topics.

Here's the scenario:
  • Field A is a text field which can have values such as Tier 0, Tier 1, Tier, 2, etc. populated by WF rules
  • Field B is a picklist for upgrading the above Tiers with 2 values, Tier 3 and Tier 4
  • Tier 3 should only be available for select if Field A is Tier 2, or if Field B itself is Tier 3 (so we can unselect the upgrade)
  • Tier 4 should always be selectable
We've used a custom snippet before for picklist rendering, but due to being JS novices, I can't seem to figure out how to incorporate a second field.

This is what we previously used for Lead Status, which was only rendering based on its own values:

var field = arguments[0],    //value = skuid.utils.decodeHTML(arguments[1]);
    value = arguments[1],
    $ = skuid.$;
    
var picklistEntries = field.metadata.picklistEntries;

// If value is Reached Out or Engaged,
// then only show those values
if ($.inArray(value,['Reached Out','Engaged'])!==-1) {
    picklistEntries.length = 0;    
    picklistEntries.push(
        { value: 'Reached Out', label: 'Reached Out', defaultValue: false, active: true },
        { value: 'Engaged', label: 'Engaged', defaultValue: false, active: true }
    );
} else if (value==='Sales Accepted') {
    picklistEntries.length = 0;   
    picklistEntries.push(
        { value: 'Sales Accepted', label: 'Sales Accepted', defaultValue: false, active: true },
        { value: 'Reached Out', label: 'Reached Out', defaultValue: false, active: true },
        { value: 'Engaged', label: 'Engaged', defaultValue: false, active: true }
    );
}


// Run the standard picklist renderer for the given mode
skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);  


Where might I start to pull in that Field A value and use that in the logic? (I really this is pretty basic, so thanks in advance)

Comments

  • Matt SonesMatt Sones 💎💎💎
    edited February 10, 2017
    Dylan,

    You need to get a reference to the model and row of the field whose data you want to use.

    In this case, I'd assume that Field A is on the same model as Field B.
    // get the model and row
    var model = field.model,
        row = field.row;
    // get the value of Field A
    var fieldA = model.getFieldValue(row,'Field_A__c');
    From there you can use an if or switch with the value of fieldA to determine what values to push into your picklist for Field B.

    Does that make sense?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!