Default value in drop down field

Hi all,

I have a drop down field in my form:

a!dropdownField(
label: "On Behalf",
labelPosition: "ADJACENT",
placeholderLabel: "--select one--",
choiceLabels: {"My Self", "Someone Else", "My Department"},
choiceValues: {"My Self", "Someone Else", "My Department"},
value: ri!requestData.onBehalfType,
saveInto: ri!requestData.onBehalfType
)

When the form loads (before any user interaction), by default, I would like the first choice to be automatically selected- "My Self".

Please how can I do this?

Thanks!

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Oof, this one is *slightly* more complicated.  Basically if the CDT containing onBehalfType is empty at the start, there's no very graceful way to pre-populate it at form load (just within the SAIL form) such that it shows the desired default value *and* saves it into the CDT - since user interaction of some sort is required to perform a save.

    By far the easiest method here might be to simply have the process instance set a default value of "My Self" in the running process before the user hits that form.  That way, the form will show the desired default value *and* the data in your CDT will have the same.

  • +1
    Certified Lead Developer
    in reply to Mike Schmitt

    As  described we can populate "My Self" by default in process instance before loading the form.
    Another way you can go with writing the code for dropdown as follows:

    value: if(isnull(ri!requestData.onBehalfType), "My Self", ri!requestData.onBehalfType),

    saveInto: a!save(ri!requestData.onBehalfType, save!value)

     

    and on form submit button:

    a!save(ri!requestData.onBehalfType, if(isnull(ri!requestData.onBehalfType), "My Self", ri!requestData.onBehalfType)).


    The method suggested by Mike is much better in terms of performance but this one is also an alternative.

Reply
  • +1
    Certified Lead Developer
    in reply to Mike Schmitt

    As  described we can populate "My Self" by default in process instance before loading the form.
    Another way you can go with writing the code for dropdown as follows:

    value: if(isnull(ri!requestData.onBehalfType), "My Self", ri!requestData.onBehalfType),

    saveInto: a!save(ri!requestData.onBehalfType, save!value)

     

    and on form submit button:

    a!save(ri!requestData.onBehalfType, if(isnull(ri!requestData.onBehalfType), "My Self", ri!requestData.onBehalfType)).


    The method suggested by Mike is much better in terms of performance but this one is also an alternative.

Children