Feature(s) impacted
Implementing an Action I would like to Get the id of selected record to fill it in a form field.
code:
{
label: "offre_id",
isReadOnly: true,
isRequired: true,
type: "Number",
defaultValue: async context=>{
console.log('context = ', context);
const id = await context.getRecordId();
console.log('==== id', id);
return id
}
},
Observed behavior
when form is loading I got this error:
On the log I got
context = ActionContextSingle {
realDataSource: DataSourceDecorator {
decorators: WeakMap { <items unknown> },
childDataSource: ChartDataSourceDecorator {
decorators: [WeakMap],
childDataSource: [DataSourceDecorator],
CollectionDecoratorCtor: [class ChartCollectionDecorator extends CollectionDecorator],
charts: [Object]
},
CollectionDecoratorCtor: [class ActionCollectionDecorator extends CollectionDecorator]
},
_caller: {
id: 74678,
email: 'adel@clevermate.fr',
firstName: 'adel',
lastName: 'djidjik',
team: 'Operations',
role: 'Operations',
permissionLevel: 'admin',
renderingId: 293219,
tags: {},
iat: 1737971620,
exp: 1737975220,
timezone: 'Africa/Algiers',
requestId: '68237ef7-54e9-44f2-aa43-e0680de38743',
request: { ip: '::1' }
},
realCollection: ActionCollectionDecorator {
childCollection: ChartCollectionDecorator {
childCollection: [SortEmulate],
dataSource: [ChartDataSourceDecorator],
charts: {},
markSchemaAsDirty: [Function (anonymous)],
lastSchema: [Object]
},
dataSource: DataSourceDecorator {
decorators: [WeakMap],
childDataSource: [ChartDataSourceDecorator],
CollectionDecoratorCtor: [class ActionCollectionDecorator extends CollectionDecorator]
},
actions: {
'Ajouter candidature': [Object],
'Affecter un programme': [Object],
'Affecter un eleve': [Object],
'Modifier un besoin': [Object]
},
markSchemaAsDirty: [Function (anonymous)],
lastSchema: {
actions: [Object],
charts: [],
countable: true,
fields: [Object],
searchable: true,
segments: []
}
},
formValues: {},
filter: Filter {
conditionTree: ConditionTreeBranch { aggregator: 'And', conditions: [Array] },
search: null,
searchExtended: false,
segment: null,
liveQuerySegment: null
},
_changedField: undefined,
queries: [],
projection: Projection(0) [],
hasFieldChanged: [Function (anonymous)]
}
error: [500] POST /forest/_actions/c_besoins/0/ajouter-candidature/hooks/load - 1429ms
===== An exception was raised =====
POST /forest/_actions/c_besoins/0/ajouter-candidature/hooks/load?{
timezone: Africa/Algiers
}
Body {
data: {
attributes: {
ids: [
1716
],
collection_name: c_besoins,
parent_collection_name: null,
parent_collection_id: null,
parent_association_name: null,
all_records: false,
all_records_subset_query: {
fields[c_besoins]: id,nb_candidatures,nb_stand_by,SA,priorité,stade,type_enum,matieres,comment,level,Lieu,contactFullName,contactWpLink,
page[number]: 1,
page[size]: 15,
filters: {\field\:\action_a_mener_enum\,\operator\:\equal\,\value\:\Trouver pépite\},
sort: -id,
timezone: Africa/Algiers
},
all_records_ids_excluded: [],
smart_action_id: c_besoins-Ajouter@@@candidature,
signed_approval_request: null
},
type: action-requests
}
}
Cannot read properties of undefined (reading '0')
TypeError: Cannot read properties of undefined (reading '0')
at ActionContextSingle.getRecordId (/home/adel/clevermate/clevermate-deploy/clevermate-forest-v2/node_modules/@forestadmin/datasource-customizer/src/decorators/actions/context/single.ts:13:23)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async defaultValue (/home/adel/clevermate/clevermate-deploy/clevermate-forest-v2/forest/c_besoins.ts:683:32)
at async ActionCollectionDecorator.dropDefault (/home/adel/clevermate/clevermate-deploy/clevermate-forest-v2/node_modules/@forestadmin/datasource-customizer/src/decorators/actions/collection.ts:259:28)
at async Promise.all (index 5)
at async ActionCollectionDecorator.getForm (/home/adel/clevermate/clevermate-deploy/clevermate-forest-v2/node_modules/@forestadmin/datasource-customizer/src/decorators/actions/collection.ts:103:31)
at async ActionRoute.handleHook (/home/adel/clevermate/clevermate-deploy/clevermate-forest-v2/node_modules/@forestadmin/agent/src/routes/modification/action/action.ts:163:18)
at async ErrorHandling.errorHandler (/home/adel/clevermate/clevermate-deploy/clevermate-forest-v2/node_modules/@forestadmin/agent/src/routes/system/error-handling.ts:24:7)
at async Logger.logger (/home/adel/clevermate/clevermate-deploy/clevermate-forest-v2/node_modules/@forestadmin/agent/src/routes/system/logger.ts:20:7)
at async bodyParser (/home/adel/clevermate/clevermate-deploy/clevermate-forest-v2/node_modules/koa-bodyparser/index.js:78:5)
===================================
Expected behavior
should Get the id of selected record and fill it in form field “offre_id”
- Project name: Clevermate v2
- Environment name: dev
- Agent technology: (nodejs,
- Agent (forest package) name & version: 1.55.1
- Database type: postgres