Hello @Kishore_Kumar
Here is a little smart action i’ve coded quickly for you. Please, read the comments on the code I’m providing, they will guide you and they will explain every steps of what needs to be performed. Observe that mainly, the field in which you want to have the dynamic values has changed, and the way we initialise the smart action form is now dynamic, meaning that based on the current record we want to execute the smart action on, the form will adapt.
By using this smart action and when the operator will validate the form, you should then be provided with the values the operator have filed in. You will then be free on what to do with these values (eg save them in your database). Here is some more info on how to handle smart action values (see the third snippet in the rails section)
class Forest::User
include ForestLiana::Collection
collection :User
action 'Commercial Mapping', type: 'single', fields: [{
field: 'unique_identifier',
type: 'Number',
is_required: false
}, {
field: 'vendor_dealer_code',
type: 'String',
is_required: false
}, {
field: 'vendor_dealer_name',
type: 'String',
is_required: false
}, {
field: 'anchor_code',
type: 'String',
is_required: false
}, {
field: 'anchor_name',
type: 'String',
is_required: false
}, {
field: 'program_code',
type: 'String',
is_required: false,
}, {
field: 'sub_program_code',
type: 'Number',
is_required: false
}, {
field: 'other_details',
#set the field to ['Enum'] to indicate multiple values can be selected
type: ['Enum'],
is_required: false
}],
#Use a load hook to prepar the form values
:hooks => {
:load => -> (context) {
#Get the id of the resource the smart action is being run for
currentRecordId = context[:params][:data][:attributes][:ids][0];
#Get the field you need to set selectable values on
otherDetailsField = context[:fields].find{|field| field[:field] == 'other_details'}
#Implement you own logic, here is a simple if..else to illustrate
if currentRecordId == '3'
#Gather the values selectable for the selected record. It can either be a database call or an API call
fetchedValues = ['test value for Steve', 'test value 2 for Steve', 'test value 3 for Steve', 'test value 4 for Steve']
else
#Gather the values selectable for the selected record. It can either be a database call or an API call
fetchedValues = ['test value for Morgan', 'test value 2 for Morgan', 'test value 3 for Morgan', 'test value 4 for Morgan']
end
#Set the selectable values in the actual field
otherDetailsField['enums'] = fetchedValues
#Return the new set of fields
return context[:fields]
}
}
end
I hope this helps, don’t hesitate if you need more help !
Steve.