Putting UDEF data into float results in an emtpy value

Hi,

 

I created a trigger that should do some calculation with sale amount and a userdefined field (decimal).

#setLanguageLevel 3;


EventData ed = getEventData();

String saleid = ed.getInputValue("SaleEntity.SaleId");
String saleAmount=ed.getInputValue("SaleEntity.Amount");
String competitorAmount=ed.getInputValue("SaleEntity.UserDefinedFields.SuperOffice:9");

Float saleAmountFloat = saleAmount.toFloat();
Float competitorAmountFloat =  competitorAmount.toFloat();

But when I do some calculation, or just put competitorAmountFloat in a text, the float is empty.

The saleAmountFloat works as expected. It feels that it has something to do with the datatype coming from the UserdefField.

 

What could be wrong here?

 

Thankx in advance for any hint in the right direction.

RE: Putting UDEF data into float results in an emtpy value

Have you tried tracing the script?

Sverre

Av: Sverre Hjelm 8. jan 2018

RE: Putting UDEF data into float results in an emtpy value

Hi Sverre,

 

Tracing gives me te following result.

ed ...
saleid 69
saleAmount 1040,6
saleAmountFloat 1040.600000
competitorAmountFloat  
premiumFloat 1.000000
premium 1.00

Strange thing, is that the variable competitorAmount is not shown.

But when I put the string competitorAmount  in the Sale Text, I get the value from it.

Av: Niels van Broekhoven 8. jan 2018

RE: Putting UDEF data into float results in an emtpy value

Hmm, when I fill my variable with a constant value "100", in stead of getting it from the eventData, it is show in the trace, and works perfect.

ed ...
saleid 69
saleAmount 1040,6
competitorAmount 100
saleAmountFloat 1040.600000
competitorAmountFloat 100.000000
premiumFloat 0.903902
premium 0.90
Av: Niels van Broekhoven 8. jan 2018

RE: Putting UDEF data into float results in an emtpy value

If you click the "..." behind ed, and expand the inputVariables, can you verify that the field you are retrieving actually has the value you expect? And that it's name is what you are using?

Sverre

Av: Sverre Hjelm 8. jan 2018

RE: Putting UDEF data into float results in an emtpy value

Ahaa.. Thanx for the tip! :)

I see it gives me not just the value, but something extra.

SaleEntity.UserDefinedFields.SuperOffice:9 [F:800.5]

Is there a function to convert this to just the actual value?

Av: Niels van Broekhoven 8. jan 2018

RE: Putting UDEF data into float results in an emtpy value

Maybe this would work?

String value = getInputValue("SaleEntity.UserDefinedFields.SuperOffice:9").after("F:").until("]");
Av: Simen Mostuen Iversen 9. jan 2018

RE: Putting UDEF data into float results in an emtpy value

For integers, we use this:

Integer ParseSuperInteger(String text)
{
  if (text.beginsWith("[I:") && text.endsWith("]"))
    return text.substitute("[I:", "").substitute("]", "").toInteger();
  return -1;
}

So, I guess for Float:

Float ParseSuperFloat(String text)
{
  if (text.beginsWith("[F:") && text.endsWith("]"))
    return text.substitute("[F:", "").substitute("]", "").toFloat();
  return -1;
}



I'm not happy with the last line, however. -1 could be a valid value. Any suggestions?

Av: Tor Thorbergsen 9. jan 2018

RE: Putting UDEF data into float results in an emtpy value

I would not return -1, but rather to a text.toInteger()/text.toFloat(). If the string does not begin with [I: or [F:, then assume it is just a number.

Sverre

Av: Sverre Hjelm 9. jan 2018

RE: Putting UDEF data into float results in an emtpy value

Thanks for the tips guys, that worked great!

Av: Niels van Broekhoven 9. jan 2018

RE: Putting UDEF data into float results in an emtpy value

Glad to hear Niels, I guess a method could be written something like this:

String getUdefValue(String field)
  return getInputValue(field).after(":").until("]");

String value1 = getUdefValue("SaleEntity.UserDefinedFields.SuperOffice:9");

String value2 = getUdefValue("SaleEntity.UserDefinedFields.SuperOffice:10");

 

Or Sverre could just make a global function doing the same thing.

Av: Simen Mostuen Iversen 10. jan 2018