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: 31
Joined: Tue Nov 10, 2020 9:07 am

field on reusable part/add to file in server module

Post by ESODevKJ »

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: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

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

Post by Dino »

*** 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: 31
Joined: Tue Nov 10, 2020 9:07 am

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

Post by ESODevKJ »

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
adale
Posts: 210
Joined: Wed Apr 08, 2020 9:18 pm
Location: Poplarville, MS

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

Post by adale »

Were you able to find out why your Server Module only had 1 record in the list?

I have a similar issue where the work list has three records in it.
The work list is being passed on to a VL View, which displays the three records.
But in my SM, the SelectList statement is only reading the first record?

At first I thought it had something to do with the key to file (and still could be), so I added the IZ Debug bit which is a simple file with no key field just to write data to. Still only get one read in the Selectlist process loop?


SELECTLIST Named(#CustList)
#IZCPPF := #W_CUSTPAY
#IZCARDNU := #W_CARDN
#IZEXPIR := #W_EXPRDT
#IZCARDTP := #W_CTYPE

* ---------- *
* IZ Debug
* ---------- *
#IZPGM := 'LSCustProf1-Z1'
#IZSTS := 'Z1'
#IZPARMS := 'STS: ' + #IO$STS + ' IZCONO: ' + #IZCONO + ' IZCUSA: ' + #IZCUSA + ' IZCPPF: ' + #IZCPPF
#IZDATE := *YYYYMMDD
#IZTIME := *TIME

INSERT Fields(*All) To_File(IZDEBG) Io_Error(*Next) Val_Error(*Next)
* ---------- *

CHECK_FOR In_File(IZCP04A) With_Key(#IZCONO #IZCUSA #IZCPPF)
IF_STATUS Is_Not(*Equalkey)
INSERT Fields(*All) To_File(IZCP04) Io_Error(*Next) Val_Error(*Next)
ELSE
UPDATE Fields(*All) In_File(IZCP04) Io_Error(*Next) Val_Error(*Next)
ENDIF

ENDSELECT
Arlyn Dale
Servias LLC
User avatar
Dino
Posts: 472
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

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

Post by Dino »

Web Page sending a list to server module works fine....

Try with this example:

Web Page:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)

Define_Com Class(#STD_AMNT.EditField) Name(#STD_AMNT) Displayposition(1) Left(36) Parent(#COM_OWNER) Tabposition(1) Top(26)
Define_Com Class(#STD_TEXTL.EditField) Name(#STD_TEXTL) Displayposition(2) Left(37) Parent(#COM_OWNER) Tabposition(2) Top(119)

Def_List Name(#list1) Fields(#std_num #std_text) Type(*WORKING) Entrys(*MAX)

Evtroutine Handling(#Com_owner.Initialize)
Define_Com Class(#test916sm.addall) Name(#AddAll)

#std_num := 5
#std_text := 'A'
Inz_List Named(#list1) Num_Entrys(100)
#AddAll.Execute List1(#list1) Std_Amnt(#STD_AMNT) Std_Textl(#STD_TEXTL)
Endroutine

End_Com
Server Module:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_SRVM)
Def_List Name(#list1) Fields(#std_num #std_text) Type(*WORKING) Entrys(*MAX)

Srvroutine Name(addall)
List_Map For(*INPUT) List(#list1)
Field_Map For(*OUTPUT) Field(#std_amnt)
Field_Map For(*OUTPUT) Field(#std_textl)

Selectlist Named(#list1)
#std_amnt += #std_num
#std_textl += #std_text
Endselect
Endroutine
End_Com
even if you prefer to write the server module with begin_loop and get_entry:

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_SRVM)
Def_List Name(#list1) Fields(#std_num #std_text) Counter(#LISTCOUNT) Type(*WORKING) Entrys(*MAX)

Srvroutine Name(addall)
List_Map For(*INPUT) List(#list1)
Field_Map For(*OUTPUT) Field(#std_amnt)
Field_Map For(*OUTPUT) Field(#std_textl)

Begin_Loop Using(#std_count) To(#LISTCOUNT)
Get_Entry Number(#std_count) From_List(#list1)
#std_amnt += #std_num
#std_textl += #std_text
End_Loop
Endroutine
End_Com
sm1.jpg
sm1.jpg (29.48 KiB) Viewed 11648 times
I have tested it even changing the INZ_LIST with 9999 entries (maximum for INZ_LIST command, but you can add more with ADD_ENTRY)
sm2.jpg
sm2.jpg (21.74 KiB) Viewed 11647 times
ESODevKJ
Posts: 31
Joined: Tue Nov 10, 2020 9:07 am

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

Post by ESODevKJ »

adale wrote: Fri Sep 17, 2021 1:48 am Were you able to find out why your Server Module only had 1 record in the list?
If I remember correctly, before I called the SM I was only saving the first entry to the list. But I've not had any other issues when taking a list from the web to the SM since, sorry!
Post Reply