How to assign the same value to multiple records

OrangePie
Member Posts: 11
Hi,
is there a way to update selected records all at once? I would like to edit unrelated records (with different value of primary key) at the same time. Is it achievable by the sheer use of a page?
is there a way to update selected records all at once? I would like to edit unrelated records (with different value of primary key) at the same time. Is it achievable by the sheer use of a page?
0
Best Answer
-
You can use a report to achieve this. Reports have a property ProcessingOnly. It removes the printing layout as well, so you don't need to worry about that.
You would need to create a function inside the report to retrieve the selected records, something likeSetTable ( newMyTable : Record "My Table") MyTable := newMyTable; //MyTable being a global Record variable of subtype "My Table"
Then you would set up value (value1, value2, etc.) for the fields that you want to modify on the Report Request Page. Users will be able to write them in (don't forget to add TableRelation if needed!) and assign them to the MyTable records in the OnPostReport() trigger:OnPostReport() IF MyTable.FINDSET THEN BEGIN REPEAT MyTable.VALIDATE("Field Name 1", value1); MyTable.VALIDATE("Field Name 2", value2); MyTable.MODIFY(TRUE); UNTIL MyTable.NEXT = 0; END;
And then, of course, change the Page Action code to call the Report's SetTable function first and then the report itself:<Action01> - OnAction() CurrPage.SETSELECTIONFILTER(MyTable); MyReport.SetTable(MyTable); //MyReport is a local variable of type Report and subtype "My Report" MyReport.RUNMODAL;
Alternatively, on your processing report you could set up "My Table" as DataItem, and then instead of the function SetTable, use SETTABLEVIEW before calling the report to set the record. And then you would write the modification code not in OnPostReport, but under "My Table - OnAfterGetRecord()".4
Answers
-
Yes, it's doable. On the page you need to create a Page Action (button) and add code that does something along these lines:
<Action01> - OnAction() //This will put the selected (marked/highlighted) records into MyTable record CurrPage.SETSELECTIONFILTER(MyTable); //MyTable here is the table which records you're displaying MyTable.MODIFYALL("Field Name", value, TRUE); //or FALSE, if you don't want MODIFY to run with TRUE parameter, default (if omitted) is FALSE
Please note that this will NOT validate the fields! In order to validate them (run code on their OnValidate triggers), you need to loop through the records, so your code becomes something like this:<Action01> - OnAction() CurrPage.SETSELECTIONFILTER(MyTable); //MyTable here is the table which records you're displaying IF MyTable.FINDSET THEN BEGIN REPEAT MyTable.VALIDATE("Field Name", value); MyTable.MODIFY(TRUE); //or FALSE); UNTIL MyTable.NEXT = 0; END;
2 -
Thanks for the quick answer. It's very helpful, though it requires the programmer to assign values in code. Is it possible to put the user in charge of modifications? I have the idea that an action would open a new page and the user would assign some values to certain fields. After accepting it all of previously selected records would have the new values. Does it sound doable?0
-
It certainly is possible for a developer to create such pages. But you'd need to know in advance what fields you want to be changed so they can be added.
Is it wise? depends what fields you want the user to change like that. (if a user is distracted and makes a typo or selects too many records)0 -
So how should I do it? I'm at a loss to know what to do. I want the page to act as a form without connecting it to any table but it's not possible, is it. If you've any idea I'd be much grateful, it's been quite a conundrum for me to solve. I'm not asking for a ready solution, just some steps I could follow or suggestions since at the moment I've tried everything I could think of.0
-
You can use a report to achieve this. Reports have a property ProcessingOnly. It removes the printing layout as well, so you don't need to worry about that.
You would need to create a function inside the report to retrieve the selected records, something likeSetTable ( newMyTable : Record "My Table") MyTable := newMyTable; //MyTable being a global Record variable of subtype "My Table"
Then you would set up value (value1, value2, etc.) for the fields that you want to modify on the Report Request Page. Users will be able to write them in (don't forget to add TableRelation if needed!) and assign them to the MyTable records in the OnPostReport() trigger:OnPostReport() IF MyTable.FINDSET THEN BEGIN REPEAT MyTable.VALIDATE("Field Name 1", value1); MyTable.VALIDATE("Field Name 2", value2); MyTable.MODIFY(TRUE); UNTIL MyTable.NEXT = 0; END;
And then, of course, change the Page Action code to call the Report's SetTable function first and then the report itself:<Action01> - OnAction() CurrPage.SETSELECTIONFILTER(MyTable); MyReport.SetTable(MyTable); //MyReport is a local variable of type Report and subtype "My Report" MyReport.RUNMODAL;
Alternatively, on your processing report you could set up "My Table" as DataItem, and then instead of the function SetTable, use SETTABLEVIEW before calling the report to set the record. And then you would write the modification code not in OnPostReport, but under "My Table - OnAfterGetRecord()".4
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions