I am a fresher currently learning . I created a table named covid19 . i want to update table field inside a form using table methods . the field must be updated when i open a form
Please start by describing the business logic that you want to implement. Just saying that you want to update a field doesn’t allow us to say what logic you need and where you should place it.
I created a table covid 19 with multiple fields . Like for example Place name and another field is Status (whether the status is “ACTIVE” or “NOT ACTIVE” ). This status field of the table . I added this field under a grid of a simple pattern form . I want know know what code to use to update the empty status Column fields with “ACTIVE” or “NOT ACTIVE” using table methods . And when i run the form the status should be updated . No complex business logic or complex algorithm needed . Simple task to update at will , one column Named “Status” in a form with “Active” or “NILL” values . I do know how to use query to update the table but that is not the task . I have to do it using table methods . Basically a task to learn regarding how one can update using table methods .
Table is named “Covid19” added to form name “Statusupdate” . Fields added under grid are PLACE NAME , STATUS .
Use an enum to represent your statuses. The first element will be the default one. If you want to set a different value, you’ll use the enum. For example:
myTable.Status = MyStatus::Active;
Before you can do it, you must think about when you want to change the status and how you’ll determine the new value.
I want update it based the Placename . for example
ttsbegin;
select forupdate data where data.Placename == “PlaceA”
data.status = “NOT ACTIVE” ;
data.update();
ttscommit;
this is a query i would use to update a table field based on another field value .
I want to do the same using code inside form methods . i hope you understood what i wanted .
No, sorry I don’t understand. Your technical solution makes no sense to me and I’m still waiting for your explanation of what business requirements you’re trying to address.
Updating the same records again everytime when you open a form looks useless from business point of view and a waste of resources from technical point.
I suspect you failed to analyze the business requirement correctly. Status typically changes when something changes in the business domain, e.g. when an order gets posted.
Please explain what the table and status represent, what is Placename and what is the business event that causes a record become active or inactive. Then we should be able to help you design a reasonable technical solution.
I think u misunderstood me . Its not for any project , just was given a training related task for learning . I understand that for a typical project related task you would need proper analysis of why i am trying to accomplish a certain task and also there will be lot of factors based on which the “status” update occurs and it does not make sense to update status based on placename . I get it but its not related to any complex project . Just trying to learn how to update any “empty field” or an “enum” in a form using form methods . I do understand the example you (when orders gets posted ) gave but its not same task , just trying learn how to update from form method .Thanks for trying to help
All right, let’s ignore all the strange requirements regarding the form, because they seem to be off your actual topic.
Let’s reduce the query to “how to update a table field”. Whether you call such code from a form or anywhere else is irrelevant, if the logic doesn’t depend on data on the form. Because you didn’t mention anything like that, I assume you don’t want it.
You need three things:
- Select the record that you want to update, and select it for update.
- Change a value of a field.
- Call update() to save the record.
For example:
ttsbegin;
select firstOnly forUpdate myTable
where myTable.PlaceName == "PlaceA"
data.Status = MyStatus::NotActive;
data.update();
ttscommit;
When it’s about updating a single uniquelly identified record, find() method is usually used instead of an explicit select statement:
ttsbegin;
MyTable myTable = MyTable::find("PlaceA", true);
data.Status = MyStatus::NotActive;
data.update();
ttscommit;
If you want to update multiple records, you could use a while select:
ttsbegin;
while select forupdate myTable
where myTable.PlaceName == "PlaceA"
{
data.Status = MyStatus::NotActive;
data.update();
}
ttscommit;
but update_recordset may be much more efficient:
update_recordset myTable
setting Status = MyStatus::NotActive
where myTable.PlaceName == "PlaceA";
When you getr familiar with the basics, looks at Query* classes as well.
And don’t forget that AX/F&O comes with documentation, and that you can find thousand examples in the standard application.
Thank You , these solutions helped me