field on reusable part/add to file in server module

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
ESODevKJ
Posts: 18
Joined: Tue Nov 10, 2020 9:07 am

field on reusable part/add to file in server module

Post by ESODevKJ » Fri Mar 26, 2021 9:53 am

Hello All,

VLFONE question, I'm using 3 duplicates in my example but I actually need this done dozens if not hundreds of times:

Let's say I have the same field 3 times on my reusable part. I have to change the name like so:

Code: Select all

Define_Com Class(#CUST.Visual) Name(#CUST) Parent(#Panel)
Define_Com Class(#CUST.Visual) Name(#CUST1) Parent(#Panel)
Define_Com Class(#CUST.Visual) Name(#CUST2) Parent(#Panel)
 
I need to insert those 3 fields into file CUSTBI. I can do something like this on the reusable part:

Code: Select all

If Cond('CUST *NE *blanks')
Add_Entry To_List(#CUSTLIST)
Endif
If Cond('CUST1 *NE *blanks')
Change Field(#CUST) To(#CUST1)
Add_Entry To_List(#CUSTLIST)
Endif
If Cond('CUST2 *NE *blanks')
Change Field(#CUST) To(#CUST2)
Add_Entry To_List(#CUSTLIST)
Endif
Then I go to my server module and loop through #CUSTLIST and add the 3 entries to CUSTBI.

My questions are,
  1. Is there a better way to go about this?
  2. Is there another way to add the same field multiple times on a reusable part?
  3. Can I just add #CUST, #CUST1, #CUST2 to list #CUSTLIST and go to server module and loop through list? I think if I do that I have to define fields #CUST1, CUST2, ETC.


Thanks in advance!

User avatar
Dino
Posts: 95
Joined: Fri Jul 19, 2019 7:49 am
Location: Tail of the Dragon, Robbinsville, NC
Contact:

Re: field on reusable part/add to file in server module

Post by Dino » Fri Mar 26, 2021 11:06 am

*** Updating this.

you could create a collection of that field, then read the collection and order the server module to save each record, or move that to a list before going to the server module.

a little bit of this post to create the fields and present them in the screen: viewtopic.php?f=3&t=2427
and this example to read the collection in the server module... https://docs.lansa.com/14/en/lansa013/c ... 6_1045.htm

I created this Web Page as example for now:

Image

Image

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Height(465) Width(881)

Define_Com Class(#STD_NUM.Visual) Name(#STD_NUM) Caption('Number of Fields') Displayposition(1) Height(19) Labeltype(Caption) Left(24) Parent(#COM_OWNER) Tabposition(1) Top(16) Width(193) Usepicklist(False)
Define_Com Class(#PRIM_PHBN) Name(#CREATE_FIELDS) Caption('Create Fields') Displayposition(3) Left(232) Parent(#COM_OWNER) Tabposition(3) Top(16) Width(113)
Define_Com Class(#PRIM_PHBN) Name(#SAVE_FIELDS) Caption('Save Fields') Displayposition(2) Left(352) Parent(#COM_OWNER) Tabposition(2) Top(16) Width(113)
Define_Com Class(#PRIM_MD.Label) Name(#Text) Caption('Text') Displayposition(4) Left(475) Parent(#COM_OWNER) Tabposition(4) Top(15) Width(302)

* Create one collection of fields Amounts
Define_Com Class(#PRIM_KCOL<#STD_AMNT.EditField #STD_NUM>) Name(#BunchOfFields) Reference(*DYNAMIC) Style(Collection)

Evtroutine Handling(#CREATE_FIELDS.Click)
If_Ref Com(#BunchOfFields) Is_Not(*null)
Set_Ref Com(#BunchOfFields) To(*null)
Endif

* Create the collection
Set_Ref Com(#BunchOfFields) To(*Create_as #PRIM_KCOL<#STD_AMNT.EditField #STD_NUM>)

Begin_Loop Using(#std_int) To(#STD_NUM)
Set_Ref Com(#BunchOfFields<#std_int>) To(*CREATE_AS #STD_AMNT.EditField)
Set Com(#BunchOfFields<#std_int>) Width(200) Displayposition(#std_int) Tabposition(#std_int) Parent(#COM_OWNER) Height(55) Top((60 * #std_int))
End_Loop
Endroutine

Evtroutine Handling(#SAVE_FIELDS.Click)
Define_Com Class(#TEST0325sm.SaveFields) Name(#Savefields)

Define Field(#total) Reffld(#STD_AMNT)
#total := 0
For Each(#Current) In(#BunchOfFields)
#total += #Current.Value
#Savefields.ExecuteAsync Std_Amnt(#Current.Value)
Endfor
#Text.Caption := #std_num.asstring + ' fields saved totalling $' + #total.asString
Endroutine
End_Com
which calls this server module:
Image

Still thinking in a nicer way to send the full collection to the server module... off course, one simple way (and better for performance so only one call to the server module) could be to read the collection and move it to a list, then send the list to the server module...

Image

Code: Select all

Evtroutine Handling(#SAVE_FIELDS.Click)
Define_Com Class(#TEST0325sm.SaveList) Name(#Savefields)

Def_List Name(#ListOfAmounts) Fields(#STD_AMNT) Type(*WORKING) Entrys(*MAX)

Clr_List Named(#ListOfAmounts)
For Each(#Current) In(#BunchOfFields)
#STD_AMNT := #Current.Value
Add_Entry To_List(#ListOfAmounts)
Endfor
#Savefields.ExecuteAsync Listofamounts(#ListOfAmounts)
Endroutine
and the server module:

Code: Select all

Def_List Name(#ListOfAmounts) Fields(#STD_AMNT) Type(*WORKING) Entrys(*MAX)

Srvroutine Name(SaveList)
List_Map For(*INPUT) List(#ListOfAmounts)
Selectlist Named(#ListOfAmounts)
Insert Fields(#STD_AMNT) To_File(LISTAMNT)
Endselect
Endroutine

ESODevKJ
Posts: 18
Joined: Tue Nov 10, 2020 9:07 am

Re: field on reusable part/add to file in server module

Post by ESODevKJ » Wed Mar 31, 2021 9:13 am

EDIT: Reading through this I realized I had the Inz_List. Problem solved.

Hi Dino,

Appreciate the response. The best solution for my particular needs was to just drop a #PRIM_LIST on my reusable part so the user would be able to add rows of data.

I ran into a different issue now: Even though there are 50 rows of data in my #prim_list in the reusable part, only the last entry is being read by the server module. In debug I see that there is only 1 entry in the list. Do you happen to have any ideas about this?


Reusable part:

Code: Select all

Evtroutine Handling(#multisave.Click)
Define_Com Class(#SVRM.multiSAVE) Name(#multi_SAVE)


Inz_List Named(#MultiList)

#multi_SAVE.Execute Multilist(#MultiList) 
endroutine
And in the server module I have:

Code: Select all

Srvroutine Name(MultiSAVE) Session(*REQUIRED)
List_Map For(*INPUT) List(#multilist)

begin_loop
Change Field(#COUNT) To('#COUNT + 1')
Get_Entry Number(#COUNT) From_List(#multilist)
Insert Fields(#multilist) To_File(CUSTBI) 
end_loop
endroutine

Post Reply