A question about scripting in the the windows client.

Version 8.2.65501025

Hi,

After an upgrade to SO 8.2 R04 we noticed that a script did work as it used to in SO 8.0

We use OnCurrentSaleFieldChanged.

In the script we check values for some fields and set values for some fields in the sale.

What happens now is that the windows client crasches.

I did a workaround that implements a kind of reentrancy protection so now it works.

If I remember correctly, before there was reentrancy protection already.

 

Best regards
Patrik

RE: A question about scripting in the the windows client.

Hi Patrik,
Can you elaborate on your use case? I'd like to reproduce this.
And yes, there are many re-entrancy guards in all models.

Conrad

Af: Conrad Weyns 16. mar 2018

RE: A question about scripting in the the windows client.

Hi Conrad,

Thank you for your answer.

I could not let this go so I tested in my own environment as well and I could not reproduce the behaviour. I have not built the script myself but I will get a copy of it and post it here. Can reentrancy protection be missing for one or more fields or is it there for the whole sale object?

 

Best regards
Patrik

Af: Patrik Lindholm 16. mar 2018

RE: A question about scripting in the the windows client.

Essentialy, we have to guard against re-entrant calls while in Delete, Cancel, Save and ChangeIdentity.

If you listen to a FieldChanged or BeforeSave message and cause another field change  (quite legal) then you will get called once more. This is not new. Our model has no knowledge of who is calling a Set method. I.o.w. no Set method has ever guarded agianst a re-entrant call.
Internaly, we propagate something called a "CallDepth" that allows us to know when the stack has unwinded so we can broadcast to our own views only once.

What I am curious about in your issue is what could have changed here in 8.2 that causes your script behaviour to change and crash the app.

Conrad

Af: Conrad Weyns 16. mar 2018

RE: A question about scripting in the the windows client.

Hi Conrad,

I will send you the script later today.

 

Best regards
Patrik

Af: Patrik Lindholm 19. mar 2018

RE: A question about scripting in the the windows client.

Here is the script.
DIm isinSaleFieldChanged
isinSaleFieldChanged = false

Sub OnCurrentSaleFieldChanged(fieldname) 
'*********************************************************************************************
' Scriptet är byggt av: 
' Rikard Fredlund 
' Generate Business
' 2013-05-02
'*********************************************************************************************
'*********************************************************************************************
' Nollställer värden så scriptet inte gör att SO kraschar.
'*********************************************************************************************
' The line below is part of my workaround - Patrik
if isinSaleFieldChanged = false then

isinSaleFieldChanged = true

DIM validation
validation = "-"
CurrentSale.UDef.ByName("testMandatory").value = ""
CurrentSale.validationmessage = ""

'*********************************************************************************************
' Sätter värdet på VG: (egendefinerat fält) efter vad som är satt i Försäljningstyp.
'*********************************************************************************************
udlisttable = CurrentSale.UDef.ByName("VG:").ListTableId

if CurrentSale.SaleType.Text = "Maskinförsäljning" then
	CurrentSale.Udef.ByName("VG:").Value = Database.GetListItemByName(udlisttable, "Maskin").Id
end if

if CurrentSale.SaleType.Text = "Reservdelsförsäljning" then
	CurrentSale.Udef.ByName("VG:").Value = Database.GetListItemByName(udlisttable, "Reservdel").Id
end if

if CurrentSale.SaleType.Text = "Serviceförsäljning" then
	CurrentSale.Udef.ByName("VG:").Value = Database.GetListItemByName(udlisttable, "Service").Id
end if

if CurrentSale.SaleType.Text = "Materialförsäljning" then
	CurrentSale.Udef.ByName("VG:").Value = Database.GetListItemByName(udlisttable, "Material").Id
end if

if CurrentSale.SaleType.Text = "Välj Försäljningstyp" then
	CurrentSale.Udef.ByName("VG:").Value = Database.GetListItemByName(udlisttable, "").Id	
end if

'*********************************************************************************************
' Kollar att alla tre fält som ska sättas är satta, om de är de sätts det dolda fältet till
' värdet 123. Om de inte är satta sätts fältet till "", fältet är mandatory och då går det
' inte att trycka på "OK" knappen (den blir grå).
'*********************************************************************************************
if not CurrentSale.SaleType.Text = "Välj Försäljningstyp" then
	if not CurrentSale.source.Text = "" then
		if CurrentSale.Amount > 0 then
			CurrentSale.UDef.ByName("testMandatory").value = "123"
		end if
	end if
end if

'*********************************************************************************************
' Kollar vilka fält som är satta och om något inte är satt skrivs detta ut i validationmessage
' (Om man håller över "OK" knappen när den är grå så visas detta värdet).
'*********************************************************************************************
if CurrentSale.SaleType.Text = "Välj Försäljningstyp" then
	validation = "Försäljningstyp måste väljas"
end if

if CurrentSale.Source.Text = "" then
	validation = validation  & vbCrLf & "Leverantör måste väljas"
end if

if CurrentSale.Amount = 0 then
	validation = validation & vbCrLf & "Belopp måste vara högre än 0"
end if
if not validation = "-" then
	CurrentSale.validationmessage = validation
end if
isinSaleFieldChanged = false
end if
End Sub
Af: Patrik Lindholm 19. mar 2018

RE: A question about scripting in the the windows client.

Hi Patrik,
I am not seeing why this script should behave differently between 8.0 and 8.2.
If the script did not have the global isinSaleFieldChanged guard before then I would expect the stack to crash if your logic hit the ValidationMessage since validation is local and ValidationMesage would get cleared and reset every time.

All Set* methods in our models guard against setting a field to the same value. I double-checked that now in the SaleModel.

Bottom line, this sort of message logic requires a global isBusy guard.


Conrad

Af: Conrad Weyns 19. mar 2018

RE: A question about scripting in the the windows client.

Hi Conrad,

Thanks.

The script did not have IsInSaleFieldChanged before. The script crashed the windows client before I added this.

The script have been working before the upgrade to 8.2

But it is working after the changes I made.

 

Best regards

Patrik

Af: Patrik Lindholm 20. mar 2018