Policy Automation for B2C Service

Get Involved. Join the Conversation.

Topic

    Annie Fisher
    Is it bad practice to access...Answered
    Topic posted October 28, 2019 by Annie FisherRed Ribbon: 250+ Points 
    23 Views, 2 Comments
    Title:
    Is it bad practice to access control._source.config.listOptions ?
    Content:

    Hi all,

    I have a requirement that a list of values be retrieved via Ajax and pushed into a drop down list.  There are several ways I can do this but one way I've tried I like but not sure if its best practice.

    I have an attribute defined on my model as type Text.  I dropped the control for this on an interview screen as type Drop Down, with a customName property of "courseSearch".

    I set the default value for the drop down to "... loading ..".  Then I wrote some JS that looks like this:

    OraclePolicyAutomation.AddExtension({
    
    customInput: function (control, interview) {
    
    if (control.getProperty("customName") == "courseSearch"){
    
    
    var newOption = {
    
    displayText : "Option1",
    
    nodeDepth:1,
    
    rawDisplayText : "RawOption1",
    
    value: "1"
    
    };
    
    
    control._source.config.listOptions.push(newOption);
    
    }
    
    }
    
    })
    

    This works really well, and in practice I would iterate over an Ajax success object to populate the list.

    My question is - it doesn't feel like best practice to access

    control._source.config.listOptions
    

    directly (even though its just an array of objects).  Is there a better way to do this?  

    Thanks in advance..

    Annie

    Version:
    OPA ver 19B
    Code Snippet:

    Best Comment

    Davin Fifield

    Anything not documented is not supported. So any future update could cause this approach to stop working!

    The currently supported approaches would be either:

    * A customOptions interview extension that returns the list options

    * A customInput interview extension that implements a custom control

    Is there a particular reason you don't want to do either of these?

    Comment

     

    • Davin Fifield

      Anything not documented is not supported. So any future update could cause this approach to stop working!

      The currently supported approaches would be either:

      * A customOptions interview extension that returns the list options

      * A customInput interview extension that implements a custom control

      Is there a particular reason you don't want to do either of these?

    • Annie Fisher

      Yes I agree, anything undocumented is a risk.  I knew there was a reason I felt uncomfortable!

      I am still new to OPA and did not know about the customOptions extension, or rather I did not realise it worked in that way.  I had been tearing my hair out previously trying to get OPA to remember options selected from screen to screen (and back again) when using the customInput to add SELECT elements.

      Thank you for your advice, this has really helped.