Automate

 View Only
  • 1.  Javascript to populate a dropdown list

    Posted 07-16-2019 10:05
    I have written a javascript but it does not do what I need it to. Can someone please tell me what is wrong with it and how to correct it?


    var CompanyCodes = document.getElementsByTagName('CompanyCodes');

    var el = document.createElement("option");

    el.text = 'Woohoo';
    el.value = 'Woohoo';

    CompanyCodes.add(el);

    $form.reloadDropDownOptions('/my:myFields/my:CompanyCodes');

    ------------------------------
    Jurgen Lootens | Consultant
    CTAC | 0123456789
    ------------------------------


  • 2.  RE: Javascript to populate a dropdown list

    Posted 07-16-2019 10:23
    I'm getting the message in the debugger that the function add is not valid.

    Does anyone know how to write this script?

    ------------------------------
    Jurgen Lootens | Consultant
    CTAC | 0123456789
    ------------------------------



  • 3.  RE: Javascript to populate a dropdown list

    Posted 07-16-2019 11:03
    Latest version of the (failing) script. I now get an error message "select_control[0] is undefined". It may be to do with the fact that  I am running the rule on loading the form...? But how else do I get it to execute and populate the dropdwn list?

    var el = document.createElement('option');
    html = "<option value='Woohoo'>Woohoo</option>";
    el.innerHTML = html;

    var cocode = document.getElementById('frm_component_select1_1');

    cocode.add(el);

    $form.reloadDropDownOptions('/my:myFields/my:CompanyCodes');


    ------------------------------
    Jurgen Lootens | Consultant
    CTAC | 0123456789
    ------------------------------



  • 4.  RE: Javascript to populate a dropdown list

    Posted 07-17-2019 08:02
    What is the use case for involving JavaScript to populate the drop down?

    I tried your code in a new solution (v12.0) and had no issue or debugger message.

    ------------------------------
    Joshua Whitener | Technical Advisor
    Exxon Mobil Corporation | 8326258441
    ------------------------------



  • 5.  RE: Javascript to populate a dropdown list

    Posted 07-18-2019 03:30
    Hi Joshua,

    We are using dropdown fields on our form but we want to limit the dropdowns based on the user authorisation. User authorisation is a list in Sharepoint with two columns: company code | username.

    I have a second list in Sharepoint with company code | Company Name

    I want the form to only show the company codes + their name that the user is registered for in the Sharepoint list. But maybe there is a better way to do this?

    ------------------------------
    Jurgen Lootens | Consultant
    CTAC | 0123456789
    ------------------------------



  • 6.  RE: Javascript to populate a dropdown list

    Posted 07-18-2019 08:04
    If you setup a data connection to the list, you can put a Query element on the view that runs on form view or whenever you'd like. Set this Query to filter by a current user field populated by a current user control and in turn populate a hidden table. Then you can set your drop down's range to "Repeating Content" and feed from that table. You'll need a reload drop down rule after the query runs.

    ------------------------------
    Joshua Whitener | Technical Advisor
    Exxon Mobil Corporation | 8326258441
    ------------------------------