Continuation line within Dependency php file

I have a Dependency file using SetOptions to present a DD List.  The reason I am using a Dependency file is there is more than one conditions involved so my understanding is I can't build a Dependent Dropdown list within Studio as that only allows one 'parent'

The DD List is quite verbose and it is critical that I get the key values and label values aligned, otherwise the incorrect key will go into the database.

To make the file more readable so that maintenance is accurate, I'd like to break the label options into different lines. I'm not a php guru so am wondering which syntax I can use as a line break. I've tried the ; as shown below but this does not appear to work. The QRR succeeds but the DD list is not presenting.

Original: (labels actually are on one line)

$dependencies['RevenueLineItems']['setoption_dep_Attest2020'] = array(
'hooks' => array("edit","save"),
// 'trigger' => 'true',
'trigger' => 'and(equal($sym_service_line_c, "1"), equal($sym_adv_std_year_c, "2020"))',
'triggerFields' => array('sym_adv_std_year_c', 'sym_service_line_c'),
'onload' => true,
'actions' => array(
array(
'name' => 'SetOptions',
'params' => array(
'target' => 'sym_adv_std_matter_c',
'keys' => 'createList("", "19", "2", "9", "5", "11", "10", "4", "8", "12", "3", "7", "6", "15", "16", "17", "18", "100", "101", "21", "20", "13", "14", "99")',
'labels' => 'createList("blank", "Label A", "Label B", "Label C", "Label D", "Label E", "Label F", "Label G", "Label H", "Label I", "Label J", "Label K", "Label L", "Label M", "Label N", "Label O", "Label P", "Label Q", "Label R", "Label S", "Label T", "Label U", "Label V", "Label W")'
),
),
),
);

Revised : (line breaks)

$dependencies['RevenueLineItems']['setoption_dep_Attest2020'] = array(
'hooks' => array("edit","save"),
// 'trigger' => 'true',
'trigger' => 'and(equal($sym_service_line_c, "1"), equal($sym_adv_std_year_c, "2020"))',
'triggerFields' => array('sym_adv_std_year_c', 'sym_service_line_c'),
'onload' => true,
'actions' => array(
array(
'name' => 'SetOptions',
'params' => array(
'target' => 'sym_adv_std_matter_c',
'keys' => 'createList("", "19", "2", "9", "5", "11", "10", "4", "8", "12", "3", "7", "6", "15", "16", "17", "18", "100", "101", "21", "20", "13", "14", "99")',
'labels' => 'createList(;
"blank",;
"Label A",;
"Label B",;
"Label C",;
"Label D",;
"Label E",;
"Label F",;
"Label G",;
"Label H,;
"Label I",;
"Label J",;
"Label K",;
"Label L",;
"Label M",;
"Label N",;
"Label O",;
"Label P",;
"Label Q",;
"Label R",;
"Label S",;
"Label T",;
"Label U",;
"Label V",;
"Label W")'
),
),
),
);


Thank you

  • I am not understanding what your dependency is trying to do, but one thing that stands out is that you added semicolons to every line in your labels list. There should not be any semicolons inside your createList regardless of how you space your elements, be it spaces or line breaks in your code.

    FrancescaS

  • Hi 

    Thanks for responding. The Dependency will present a DD List based on options chosen on 2 other fields. The full DD List in Studio has over 100 entries and will grow over time. So the user chooses a Service Line and a Year and the Dependency file offers up an abbreviated list based on those choices.

    The example above is one section of the Dependency file covering one of those choice combinations - 'only' 23 items in the DD list

    FYI, the keys list are fixed ids needed for a separate database we are integrating with - hence their apparent random order, as the labels are being presented in alphabetical order.

    I'm trying to make the code more readable for maintenance purposes and having the 23 label options on one line is difficult to read (I've used Label A, Label B as examples. The real labels are longer)

    So I'm trying to use a line break character (I could be totally wrong in my understanding for that need) such that the Dependency file sees the Labels CreateList line as one line. I think if I put the choices on different lines without some kind of continuation indicator it doesn't present the list. So I have made the assumption it does need some kind of continuation indicator and I simply tried the ; as I've seen this is some general php posts - hence my original question.

    Hope that makes sense.

    Neil 

  • ok, I understand. As the documentation says "The createList() function is a JavaScript function from Sidecar.  It requires a comma delimited quote enclosed list of options. "

    Maybe you could try something like this (I've not tried this myself so take it with a grain of salt) 

    It is a bit of a different way of doing things, and possibly considered a bit of a "hack", but it will help you keep your keys and values in a way that you can read them, and it sounds to me like these lists will be a bit of a nightmare to maintain... 

    Create an array of "key"=>"value" pairs and then use PHP to create the comma delimited quoted lists for you.

    This way you keep your key/value pairs clean and easy to read.

    $dropdown_array_Attest2020 = array(
      "19"=>"Label A",
      "2" => "Label B",
      "9"=> "Label C"
    );
    $keys_list_Attest2020 = '"'. implode('","', array_keys($dropdown_array_Attest2020)). '"';
    $labels_list_Attest2020 =  '"'. implode('","', array_values($dropdown_array_Attest2020)) . '"';
    
    $dependencies['RevenueLineItems']['setoption_dep_Attest2020'] = array(
        'hooks' => array("edit","save"),
        'trigger' => 'and(equal($sym_service_line_c, "1"), equal($sym_adv_std_year_c, "2020"))',
        'triggerFields' => array('sym_adv_std_year_c', 'sym_service_line_c'),
        'onload' => true,
        'actions' => array(
            array(
                'name' => 'SetOptions',
                'params' => array(
                'target' => 'fruits_c',
                'keys' => 'createList({$keys_list_Attest2020})',
                'labels' => 'createList({$labels_list_Attest2020})'
            ),
          ),
        ),
    );

    Let me know if this works ;)

    The other option is to generate the dropdown list in code, I did something similar here:

    https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/2019/create-dropdown-from-module-records/7425#7425

    In that case I would suggest that you consider building a module to maintain these options so that an admin can easily add new values, or change values, for your dropdown without having to update the code every year.

    If I had a better understanding of your business need, perhaps I could suggest other solutions that are less maintenance-heavy.


    FrancescaS

  • One more thought, if you want to approach this in Javascript you could maintain the lists in your dropdown lists in Sugar, and just change the name of the dropdown list to load based on the other two fields.

    For example you have values from your dropdowns: "Attest" and "2020" you concatenate the two values and get Attest2020

    then in your dropdowns you define one called Attest2020 and programmatically set the dropdown values to those defined in the Attest2020 dropdown.

    This requires javascript coding... and I've not done it with TWO dropdowns but maybe it's one way to solve it...


    See: 

    sugarclub.sugarcrm.com/.../24845