10 December 2015
Latest tip from Graham Smith in his Peoplecode Friday blog series...
A number of times in my PeopleSoft career I have been asked by users if I can provide a paste from the Windows clipboard into a grid. Typical use cases include pasting Excel data into a grid or bulk loading text.
|PIA Page with paste window and results grid
|App Designer Page
Local Rowset &rs = GetRowset(Scroll.GRS_TBL);
Local array of string &aRows;
Local array of string &aFields;
&aString = CreateArray("");
&aFields = CreateArray("");
&aRows = Split(GRS_WRK.HTMLAREA, Char(10));
For &i = 1 To &aRows.Len &aFields = Split(&aRows [&i], "|");
&rs(&i).GRS_TBL.SELNUM.Value = &aFields ;
&rs(&i).GRS_TBL.DESCR.Value = &aFields ;
- You can obviously change the separator from | (pipe) to whatever works for you. Comma is useful when pasting from Excel.
- You will want to add some structure checking code. If you're expecting 2 fields but a user pastes 3 then you'll want to trap that.
- You may want to do some datatype validation to avoid generating PeopleCode or component processor errors.
- You could get really smart and create a button which reads data directly from the clipboard. Most browsers don't allow you to do this for security reasons but there are ways to configure browsers to trust the clipboard.
- I've been using this recently to repeatedly flush and reload data into tables on a new application I've been building. I went as far as making the table name a parameter and setting GETFIELD(n).Value rather than an explicit field name as I had numerous tables to populate.
Any other ideas or suggestions then, as usual, just post comments.