VLF-ONE SWITCH question

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
LANSAGuru
Posts: 29
Joined: Thu Mar 24, 2016 5:31 am

VLF-ONE SWITCH question

Post by LANSAGuru » Wed Aug 23, 2017 7:43 am

Use Case:

Two Business Objects share a command handler.
The command handler adds records to a file(s) and adds an instance to BO #1 (this command handler is attached to a command for both BO #1 and BO #2).
After adding the record(s) we clear the instance list for BO #1, switch to it from BO #2 if we are in BO #1, load the instance list with the records just added, then open a command handler for BO #2 (probably the default command) and load the current instance.

This would seem to be a fairly common scenario, but it was a little tricky working out how it works.

We have this.

BO #2 Command Handler
insert data

Code: Select all

.
insert records
#AVFRAMEWORKMANAGER.avSwitch Toobjectnamed(BO1) Caller(#COM_OWNER) Wait(True)
* #COM_OWNER.avSignalEvent Withid(Load_Opportunity) To(APPLICATION) Sendainfo1(#thekeyjustadded) - this doesn't work comment out
#Timer1.INTERVAL := 100
#Timer1.START
.
Evtroutine Handling(#Timer1.Tick)
#Timer1.Stop
#COM_OWNER.avSignalEvent Withid(Load_Opportunity) To(APPLICATION) Sendainfo1(#thekeyjustadded)
Endroutine
Why?
The Wait(True) doesn't actually seem to wait. So when you attempt the signal, the Filter for BO#1 doesn't see the event.
If you put in a slight delay before doing the signal, then the filter for BO#1 can see the event.
Is this a bug perhaps?

BO#1 Filter

This is just a test case.
Employee is BO#1
Departments is BO#2
I named the objects here BO1 and BO2 in the code for clarity

Code: Select all

Evtroutine Handling(#Com_owner.avEvent) Withid(#EventId) Withainfo1(#pEmployeeKey)

Define_Com Class(#A106S.Find) Name(#Find)

Group_By Name(#xEmployee) Fields(#xEmployeeIdentification #xEmployeeTitle #xEmployeeSurname #xEmployeeGivenNames #xEmployeeDateofBirth #xEmployeeGender #xEmployeeStreet #xEmployeeCity #xEmployeeState #xEmployeePostalCode #xEmployeeCountry #xEmployeeHomeTelephone #xEmployeeBusinessTelephone #xEmployeeMobilePhone #xEmployeeSalary #xEmployeeStartDate #xEmployeeTerminationDate #xDepartmentCode)

#vf_elIdn := #EventId.Value

Case (#vf_elIDN)
When Value_Is(= Load_Opportunity)

#avListManager.ClearList

#xEmployeeIdentification := #pEmployeeKey
#Find.Execute Xemployeeidentification(#xEmployeeIdentification) Xemployee(#xEmployee)
#UF_VISID1u := #xEmployeeIdentification
#UF_VISID2u := #xEmployeeSurname
#avListManager.AddtoList Visualid1(#UF_VISID1u) Visualid2(#UF_VISID2u) Akey1(#xEmployeeIdentification) Acolumn1(#xEmployeeGivenNames) Setascurrent(True) Select(True) Executedefaultcmd(True)

#AVFRAMEWORKMANAGER.avSwitch Toobjectnamed(BO1) Caller(#COM_OWNER) Execute(COMMAND_DETAILS)

Endcase

So here there is a command Executedefaultcmd(True) on the addtolist, but it doesn't appear to do anything.
To open up the command handler programmatically, one needs to execute a switch here and use the EXECUTE command

This seems to work pretty well except for the following.
The timer seems like a hack.
The Executedefaultcmd doesn't appear to do anything.

QUESTIONS

Is this best practice for this use case?
Is the Executedefaultcmd not doing anything a bug?
Is the WAIT(True) not appearing to do anything a bug, or are we misunderstanding what it is doing?

NOTE: This is using EPC1410343

MarkD
Posts: 318
Joined: Wed Dec 02, 2015 9:56 am

Re: VLF-ONE SWITCH question

Post by MarkD » Wed Aug 23, 2017 11:47 am

The wait(True) does work I think - it creates a 2 millisecond delay before running the transaction queue.
The problem is probably that executing commands always involves a wait - and it longer than 2 ms I think.

MarkD
Posts: 318
Joined: Wed Dec 02, 2015 9:56 am

Re: VLF-ONE SWITCH question

Post by MarkD » Wed Aug 23, 2017 11:49 am

The executeDefaultcommand on the addtolist does not work - its on the list to be changed.

The newer way to do that is to get back a reference to the data it created and ask it to execute it's default command.

eg: Define_Com Class(#vf_LM003O) Name(#NewEmployeeItem) Reference(*DYNAMIC)

#avListManager.AddtoList Visualid1(#UF_VISID1u) Visualid2(#UF_VISID2u) Akey1(#xEmployeeIdentification) Acolumn1(#xEmployeeGivenNames) Setascurrent(True) Select(True) Dataitem(#NewEmployeeItem)

#NewEmployeeItem.avExecuteDefaultCommand

MarkD
Posts: 318
Joined: Wed Dec 02, 2015 9:56 am

Re: VLF-ONE SWITCH question

Post by MarkD » Wed Aug 23, 2017 12:14 pm

In this type of situation the new avSwitch parameters CallerReference() and StartFilterorInstanceList() are worth knowing about because they make things a little simpler than in VLF-WIN programming:

StartFilterorInstanceList helps with the perennial problem with starting up the target business object when it is not currently open.

CallerReference is useful to avoid having to make (or in this case, carefully time) event signals.

The uExecute method in the target business object’s command handler has a SwitchCallerReference parameter which receives whatever the ‘switchee’ passed in the CallerReference parameter.

The CallerReference can be a compound object reference when you want to pass lots of stuff- but most often it is very simple, like this:

Switchee says:
Define_Com Class(#Empno) Name(#SendEmployeeNumber)
#SendEmployeeNumber := A0090
#AVFRAMEWORKMANAGER.avSwitch Toobjectnamed(BO1) Caller(#COM_OWNER) Callerreference(#SendEmployeeNumber)

Target command handler does this to receive the value:
Define_Com Class(#Empno) Name(#SentEmployeeNumber) Reference(*DYNAMIC)
#SentEmployeeNumber <= #SwitchCallerReference *As #Empno

LANSAGuru
Posts: 29
Joined: Thu Mar 24, 2016 5:31 am

Re: VLF-ONE SWITCH question

Post by LANSAGuru » Wed Aug 23, 2017 2:50 pm

Some of this appears to not be in the documentation yet.

..Dataitem(#NewEmployeeItem)
#NewEmployeeItem.avExecuteDefaultCommand

works beautifully

the Callerreference, SwitchCallerReference parms look very useful.
SwitchCallerReference is not accesible within the filter, so for this case I would need to update the instance list from the command handler in the targeted BO. I had some problems with StartFilterAndInstanceList (assuming the or was a typo?). I need to play with this a bit more to see what is possible.

Thanks for the info!

jyoung
Posts: 351
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: VLF-ONE SWITCH question

Post by jyoung » Thu Aug 24, 2017 11:29 pm

IMHO, it would be really nice to have a uExecute method in the Filter that would get executed after uInitialize and on a avSwitch a lot like how uExecute gets invoked for commands.

This would save me quite a bit of code using managers / controllers to kick off a filter to load the instance list.

LANSAGuru
Posts: 29
Joined: Thu Mar 24, 2016 5:31 am

Re: VLF-ONE SWITCH question

Post by LANSAGuru » Fri Aug 25, 2017 12:29 am

Joe,

I like the idea.

In VL this is trivial...you would normally just add a mthroutine and run it.
In this case however I don't know how to get a handle to the filter to do that.

I like the idea of being able to kick of an ARBITRARY mthroutine in the filter or command a handler. It is possible everything needed is there now. I have (sadly) not done too much work in VLF ONE, instead working below the covers in straight VL Web. But I am now getting into this area, but some of my problems could be learning curve related. There appear to be some new things in EPC141034 as well which could apply here.

If I work out anything elegant, I will post it.
Watch this space.

MarkD
Posts: 318
Joined: Wed Dec 02, 2015 9:56 am

Re: VLF-ONE SWITCH question

Post by MarkD » Fri Aug 25, 2017 9:51 am

You should have a think about using your own custom framework manager.
That allows you to link stuff up and communicate however you please and its generally faster than the equivalent VLF generic feature.

See http://docs.lansa.com/14/en/lansa048/in ... 8_6115.htm

Note the superseded message at the start of this doco now -http://docs.lansa.com/14/en/lansa048/in ... 8_0850.htm

The new Common Activities feature can create a custom framework manager for you and snap it into your framework:
Capture5.PNG
Capture5.PNG (14.33 KiB) Viewed 227 times

jyoung
Posts: 351
Joined: Thu Jan 21, 2016 6:43 am
Location: Oklahoma City, OK USA

Re: VLF-ONE SWITCH question

Post by jyoung » Thu Oct 19, 2017 4:00 am

LANSAGuru, did you ever find a solution to the timer hack?

I am running into the same problem where I am switching to an object, but instead of signalling with avSignalEvent I am invoking a method on my object manager that "should" trigger the filter. The problem is that the Filter has not been initialized yet, so it can't be used.
Trace Output.PNG
Trace Output.PNG (30.6 KiB) Viewed 128 times
Using a timer to wait (because the actual wait does not appear to be waiting) works.

Code: Select all


mthroutine name(SwitchToCreditControlPanel)
define_map for(*INPUT) class(#wk_OfficeNumber) name(#officeNumber)
define_map for(*INPUT) class(#wk_ControlNumber) name(#controlNumber)


#avFrameworkManager.avSwitch caller(#COM_OWNER) toobjectnamed(CMG_CREDIT_CONTROL_PANEL) wait(True)

#CMGCCPObjectManager.SwitchToAndLoadNumberFilter
* #avFrameworkManager.avRecordTrace component(#COM_OWNER) event("Starting Timer")
* #timer.Start

endroutine


evtroutine handling(#timer.Tick)
#avFrameworkManager.avRecordTrace component(#COM_OWNER) event("Timer Tick")

#timer.Stop
#CMGCCPObjectManager.SwitchToAndLoadNumberFilter
endroutine
With the timer in place, the filter is loaded and ready to go.
Trace Output 2.PNG
Trace Output 2.PNG (35.89 KiB) Viewed 128 times

Post Reply