Updating amount in SaleEntity with crmscripts' trigger

Not sure where to place this question. 

I am trying to create a crmscript trigger (before save sale) that will update the sale amount based on custom calculations,

e.i sum of userdefined fields.

I am able to retrieve all the values from the userdefined fields,

sample code:

EventData ed = getEventData();

String av1 = ed.getInputValue("SaleEntity.UserDefinedFields.SuperOffice:2").after("F:").until("]");
String av2 = ed.getInputValue("SaleEntity.UserDefinedFields.SuperOffice:6").after("F:").until("]");
String av3 = ed.getInputValue("SaleEntity.UserDefinedFields.SuperOffice:7").after("F:").until("]");

Float totalAmount = av1.toFloat() + av2.toFloat() + av3.toFloat();

ed.SetOutputVale("SaleEntity.Amount", totalAmount.toString(2));

 

Unfortunately, this didn't work and I am getting this error:

"Property .Amount was not found in data object"

Any suggestions?

 

Thanks.

 

 

 

 

 

 

RE: Updating amount in SaleEntity with crmscripts' trigger

Hello Paul,

This should work:

EventData eventData = getEventData();

Float av1 = decodeDBValue(eventData.getInputValue("SaleEntity.UserDefinedFields.SuperOffice:2")).toFloat();
Float av2 = decodeDBValue(eventData.getInputValue("SaleEntity.UserDefinedFields.SuperOffice:6")).toFloat();
Float av3 = decodeDBValue(eventData.getInputValue("SaleEntity.UserDefinedFields.SuperOffice:7")).toFloat();

Float totalAmount = av1 + av2 + av3;

eventData.setOutputValue("SaleEntity.Amount", totalAmount.toString(2));

 

Av: David Hollegien 16. nov 2018

RE: Updating amount in SaleEntity with crmscripts' trigger

Hi David,


Thanks for your suggestion. I'm still getting the same error: 

Property .Amount was not found in data object.

 

My initial code used the same setOutputValue("SaleEntity.Amount", totalAmount.toString(2));

(just having typos in the post with uppercase 'S')

 

Av: Paul Guanio-Uluru 16. nov 2018

RE: Updating amount in SaleEntity with crmscripts' trigger

Hello Paul,

Strange that you are getting this error.

What SuperOffice version are you running? or are you on SuperOffice Online?

Also, is the trigger running on a sale where the amount is locked? (Quote system?)

Av: David Hollegien 16. nov 2018

RE: Updating amount in SaleEntity with crmscripts' trigger

I'm on Online environment, version 8.4

I tried using setOutputValue function on an userdefined field and it worked.

I am not using Quote, just trying to update the amount field on the sale card.

Very strange that the SaleEntity.Amount reported the error.

Maybe a bug? Hope some crmcripts guru can clarify this.

 

 

Av: Paul Guanio-Uluru 16. nov 2018

RE: Updating amount in SaleEntity with crmscripts' trigger

There is something fishy here. I'm getting the same error in my local 8.4 R03 using this script:

#setLanguageLevel 3;

EventData ed = getEventData();
Float amount = ed.getInputValue("SaleEntity.Amount").toFloat();

//Makes sure we actually found the amount.
assert(amount > 0.0);
//Double the sale amount
amount = amount * 2;
//Set the new amount
ed.setOutputValue("SaleEntity.Amount", amount.toString(2));

Error:

I smell a bug.

Av: Frode Lillerud 16. nov 2018

RE: Updating amount in SaleEntity with crmscripts' trigger

Just tried setting "SaleEntity.Amount" on the SuperOffice Online Prod & SOD environments, both work correctly.

Also works correctly on our Onsite 8.4 R03 installation...

Strange issue!

Av: David Hollegien 16. nov 2018

RE: Updating amount in SaleEntity with crmscripts' trigger

For future reference, this happens when setting amount to a decimal value. Setting to an integer value fixes it.

Av: Frode Lillerud 22. dec 2020

RE: Updating amount in SaleEntity with crmscripts' trigger

Decimal sign confusion? "1,23" vs "1.23" ?

Av: Christian Mogensen 22. dec 2020

RE: Updating amount in SaleEntity with crmscripts' trigger

Yes, it works with comma, but not period.

ed.setOutputValue("SaleEntity.Amount", "3.14"); //Does not work
ed.setOutputValue("SaleEntity.Amount", "3,14"); //Works

However, this code does NOT work;

Float pi = 3.14159;
ed.setOutputValue("SaleEntity.Amount", pi.toString(2));
Av: Frode Lillerud 22. dec 2020

RE: Updating amount in SaleEntity with crmscripts' trigger

The server's locale setting is Norwegian I suspect, causing the C++ locale engine to switch to the scandihoovian decimal sign.

These values are all serialized to/from the NetServer entities, so the parser should be able to handle "[I:123]" or "[F:123.45]"

Need some helper functions here.  float.toInvariantString(2) and/or float.toEncodedString()

Av: Christian Mogensen 22. dec 2020