Expression evaluation error [evaluation ID = ] in rule 'pa_addvehicle' at function 'todate' parameter 1 [line 75]: PA Vehicle can only be indexed into using square brackets or the index function
Discussion posts and replies are publicly visible
Can you post the part of the code where the error comes from?
Better to use the index() function for indexing objects as suggested in the error message.
validations: if(todate(ri!vehicle.vehicleNextMaintenanceDate) <todate(ri!vehicle.vehicleLastMaintenanceDate), "The next maintenance date must be after the last maintenance date.", null)
),
Please put the code of the component you are using, not only the validation part.
Also, what type of object is the ri!vehicle? Is it a CDT or an array ?
If you are working on the Acme application example I guess the ri!vehicle is the CDT:
'type!{urn:com:appian:types}AA_Vehicle'()
In this CDT the vehicleNextMaintenanceDate and vehicleLastMaintenanceDate fields are of type Date so there is no reason to cast them again into date type:
todate(ri!vehicle.vehicleNextMaintenanceDate) < todate(ri!vehicle.vehicleLastMaintenanceDate)
a!localVariables( local!category: rule!AA_GetReferenceData(type: "Category"), local!status: rule!AA_GetReferenceData(type: "Status"), local!condition: rule!AA_GetReferenceData(type:"Condition"),a!formLayout( label: "ADD VEHICLE", contents: { a!columnsLayout( columns: { a!columnLayout( contents: { a!textField( label: "Model", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{54792ae7-b982-4e9b-a065-38f833520e00}vehiclemodel'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{54792ae7-b982-4e9b-a065-38f833520e00}vehiclemodel'], characterLimit: 55, required: false ), a!textField( label: "Make", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{ee759ec4-7f80-43f0-9e33-ff60699dadc8}vehiclemake'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{ee759ec4-7f80-43f0-9e33-ff60699dadc8}vehiclemake'], characterLimit: 55, required: false ), a!textField( label: "Color", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{f931fba7-4fbf-430e-8ed0-f733dafe5b17}vehiclecolor'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{f931fba7-4fbf-430e-8ed0-f733dafe5b17}vehiclecolor'], characterLimit: 55, required: false ), a!integerField( label: "Mileage", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{41847dfb-6e57-46d9-9a11-1c793dd9ee44}vehiclemileage'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{41847dfb-6e57-46d9-9a11-1c793dd9ee44}vehiclemileage'], required: false ), a!textField( label: "VIN", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{a8f2de8e-f628-4515-ab55-360341cdbbca}vehiclevin'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{a8f2de8e-f628-4515-ab55-360341cdbbca}vehiclevin'], characterLimit: 17, required: false ), a!dateField( label: "Next Maintenance", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{f3c174c0-2185-4448-95c2-0b66847d3de5}vehiclenextmaintenancedate'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{f3c174c0-2185-4448-95c2-0b66847d3de5}vehiclenextmaintenancedate'], required: false ) } ), a!columnLayout( contents: { a!integerField( label: "Year", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{9f20cb6e-bcf5-4fc8-9f4d-0ae08b633c67}vehicleyear'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{9f20cb6e-bcf5-4fc8-9f4d-0ae08b633c67}vehicleyear'], required: false ), a!dateField( label: "Last Maintenance", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{3eaef3a8-ad19-4e10-bbf4-b07b6944ab3e}vehiclelastmaintenancedate'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{3eaef3a8-ad19-4e10-bbf4-b07b6944ab3e}vehiclelastmaintenancedate'], required: false, validations: if(todate(ri!vehicle.vehicleNextMaintenanceDate) < todate(ri!vehicle.vehicleLastMaintenanceDate), "The next maintenance date must be after the last maintenance date.", null)
), a!dateField( label: "Date Added", labelPosition: "ABOVE", value: today(), saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{b720b92c-7bba-4ff2-bb4d-e44852afee63}vehicledateadded'], required: false, readOnly: true ), a!dropdownField( label: "Category", labelPosition: "ABOVE", placeholder: "--- Select a Value ---", choiceLabels: local!category['recordType!{0063da9e-52e1-4f6e-af28-f0fa2eefe66f}Category.fields.{142b6584-3be7-42c3-852f-600471549007}label'] , choiceValues: local!category['recordType!{0063da9e-52e1-4f6e-af28-f0fa2eefe66f}Category.fields.{94d01ec3-9cb9-412c-833a-268fe696c610}id'], value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{7ad2c969-c93d-4915-b1e4-1a69b95de838}vehiclecategory'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{7ad2c969-c93d-4915-b1e4-1a69b95de838}vehiclecategory'], searchDisplay: "AUTO", required: true, validations: {} ), a!dropdownField( label: "Status", labelPosition: "ABOVE", placeholder: "--- Select a Value ---", choiceLabels: local!status['recordType!{359c9a34-94c4-4e7f-aa46-54f9b6b5a454}Status.fields.{c192b0cc-7bdf-4bf9-aea4-eca350786546}label'], choiceValues: local!status['recordType!{359c9a34-94c4-4e7f-aa46-54f9b6b5a454}Status.fields.{8861f86e-a4ab-4e54-9c51-75fc2cad210d}id'], value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{9be749ac-1fbf-42bf-bc6b-7ab58c11bf3c}vehiclestatus'], saveInto: {}, searchDisplay: "AUTO", required: true, validations: {} ), a!dropdownField( label: "Condition", labelPosition: "ABOVE", placeholder: "--- Select a Value ---", choiceLabels: local!condition['recordType!{b86e3be8-f076-4bf4-9f37-ba3d2ecd6815}Condition.fields.{1b84c63a-9805-4988-844c-2bb03b83abe8}label'], choiceValues: local!condition['recordType!{b86e3be8-f076-4bf4-9f37-ba3d2ecd6815}Condition.fields.{44e3243e-afcf-4fe8-a200-853d2d522703}id'], value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{0c4fee03-ae4c-4d1e-8aff-a81b01dc833d}vehiclecondition'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{0c4fee03-ae4c-4d1e-8aff-a81b01dc833d}vehiclecondition'], searchDisplay: "AUTO", required: true, validations: {} ), a!fileUploadField( label: "Image", labelPosition: "ABOVE", target: cons!PA_DOCUMENTS_FOLDER_POINTER, maxSelections: 1, value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{b9c5efac-ec91-4a62-ba1d-0528930b4f9c}vehicleimage'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}PA Vehicle.fields.{b9c5efac-ec91-4a62-ba1d-0528930b4f9c}vehicleimage'], required: true, validations: {} ) } ) } ) }, buttons: a!buttonLayout( primaryButtons: { a!buttonWidget( label: "Submit", saveInto: a!save(ri!vehicle.vehicleDateAdded, today()), submit: true, style: "PRIMARY", validate: true ) }, secondaryButtons: { a!buttonWidget( label: "Cancel", value: true, saveInto: ri!cancel, submit: true, style: "NORMAL", validate: false ) } )))
fyi: please put super-long snippets of code (or, any snippets of code) in a Code Box - this both saves the length of the thread from getting blown out of the water by single comments that take up screenfuls of room, as well as preserving indentation (as well as using a friendlier, monospace font for reading).
Since ri!vehicle is a record type, you can't refer to it like this:
ri!vehicle.vehicleLastMaintenanceDate
This is the way we are referring to CDT fields.
The proper way to refer to a record type field is:
ri!vehicle[recordType!Vehicle.fields.vehicleLastMaintenanceDate]
Here is the part of the code that is giving you the error (fixed):
a!dateField( label: "Last Maintenance", labelPosition: "ABOVE", value: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}.fields.{3eaef3a8-ad19-4e10-bbf4-b07b6944ab3e}'], saveInto: ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}.fields.{3eaef3a8-ad19-4e10-bbf4-b07b6944ab3e}'], required: false, validations: if( todate(ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}.fields.{f3c174c0-2185-4448-95c2-0b66847d3de5}']) < todate(ri!vehicle['recordType!{daaebabb-0af7-4cd6-b5ae-12bff43fe006}.fields.{3eaef3a8-ad19-4e10-bbf4-b07b6944ab3e}']), "The next maintenance date must be after the last maintenance date.", null ) )
I saw that you have done the same mistake again in your code so you have to fix it also.
Helpful !! Thank you