Execute query rule in dropdown from UI values

Hello, 

I am trying to populate a dropdown by executing a query rule that is based on a CDT. I would need UI values to be passed as parameters to the query rule and populate dropdown dynamically when the user input value changes.  Issue is the value does not change when passed to query rule as a parameter and seems to take the original value only. 

Below is the code that I got so far: 

a!textField(
label: "Mfg Org",
labelPosition: "ADJACENT",
value: ri!expediteline.item_mfg_org_code,
saveInto: {
a!save(
local!mfgShipMethods,rule!EXP_GetMfgShipMethodsByOrg(local!itemMfgOrgCode,if(isnull(ri!expediteline.mfg_source_org_code_2),
if(ri!expediteline.mfg_source_org_code=local!itemMfgOrgCode,ri!expediteline.ship_from,ri!expediteline.mfg_source_org_code),ri!expediteline.mfg_source_org_code_2))
),
a!save(local!itemMfgOrgCode,ri!expediteline.item_mfg_org_code)

},
refreshAfter: "UNFOCUS",
required: true,
readonly: false,
validations: {}
)

Here I am trying to save the text field value from UI into a local variable and pass as parameter to the query rule.

Thanks

  Discussion posts and replies are publicly visible

Parents
  • Hi bpmnewb,


    can you give more clarity on your issue. In which local variable you want to store values and which is rule ?
    There is one rule which you are calling here : rule!EXP_GetMfgShipMethodsByOrg , what it suppose to return and take as input. I tried to implement the same thing in my machine and it worked.


    If possible please provide more code.

    Regards
    Abhay
  • Hi ,
    Query rule i s supposed to take value entered (ri!expediteline.item_mfg_org_code) on the text field as input and execute the query rule that would populate another dropdown field. Below is the code for the dropdown field:

    a!dropdownField(
    label:"Mfg Ship Methods",
    labelPosition: "ADJACENT",
    placeholderLabel: "--- Select a Value ---",
    choiceLabels: if(count(local!mfgShipMethods)>0,index(local!mfgShipMethods,"ship_method",null),{}),
    choiceValues: if(count(local!mfgShipMethods)>0,local!mfgShipMethods.ship_method,{}),
    value:ri!expediteline.iso_ship_method,
    saveInto: ri!expediteline.iso_ship_method,
    validations: {}
    )
    Local variable local!mfgShipMethods is populated in the load section of the page initially:

    local!mfgShipMethods : rule!EXP_GetMfgShipMethodsByOrg(ri!expediteline.item_mfg_org_code,ri!expediteline.mfg_source_org_code),

    I need local!mfgShipMethods executed every time when the user input ri!expediteline.item_mfg_org_code changes from UI.

    Thanks,
  • Hello,
    I came across this post: community.appian.com/.../load-and-with-function-difference
    which explains differences between load and with functions in UI. According to this, Variables defined in load() instantiate for only once whereas variables defined in with() will be evaluated for each interaction on form, like sort, search, input a value in field etc. However forcefully you can dynamically change the value of the variables defined on load() as well.
    In this case, I am using local variable in load section initially and would like to get it executed dynamically when the value changes and save data into the local variable again. Is with() a better option in my case?

    Thanks,
  • Hi,

    It is best example of usage of load and with function . You can also try the below way , instead of query rule i created a rule which simply contains array.


    getName rule have below :

    load(

    local!data:{{id:"1",Name:"Abc1"},
    {id:"1",Name:"Abc2"},
    {id:"2",Name:"Abc3"},
    {id:"2",Name:"Abc4"},
    {id:"3",Name:"Abc5"},
    {id:"4",Name:"Abc6"},
    {id:"4",Name:"Abc7"}},


    index(index(local!data,"Name",null),wherecontains(ri!id,touniformstring(index(local!data,"id",null))))

    )
    And interface will have this code :

    load
    (
    local!Name:null,


    {

    a!textField(
    label:"Endter Id",
    value:ri!id,
    saveInto:
    {
    ri!id,

    a!save(local!Name,rule!findingNotNullAttributes(id: ri!id))



    }

    ),

    a!dropdownField(
    label:"Name",
    placeholderLabel: "--select--",
    choiceLabels: local!Name,
    choiceValues: local!Name
    )

    }




    )
    So now in your case instead of getName, call your rule and pass the value.
  • Hi ,
    Thanks. Will try that.
    Also as the other post suggests, how do we forcefully the value of the variables defined on load() ?

    Thanks,
  • Hello ,
    That worked. I tried using with() as well which worked too. Thanks for your suggestion.

    Thanks
Reply Children
No Data