and it goes pretty well. But when I try to modify it in method I dont know what syntax I have wrong. Toolkit is at this point useless to me.
Also I've changed type of Field to AttributeDecimal because during instalation it was writing some error.
public function Maximumofthree()
{
parent::OnInsert();
$x->Get('Field1');
$y->Get('Field2');
$z->Get('Field3');
$c = max($x,$y,$z);
$this->Set('FieldMax',$c->Format(AttributeDecimal::GetInternalFormat()));
}
Any suggestion what to fix?
Last edit: razsalgul1635 2023-07-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yeah I've also tried this and wasnt working aswell. Also Ive tried replacing $this->Set('FieldMax',$c);
with
$this->Set('FieldMax',5);
and it didnt even set field to "5" which was odd.
Last edit: razsalgul1635 2023-07-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I want to make custom field in custom object which needs to compute maximum value from three fields.
Field 01 looks this way: (field 01/02 and 03 are identical)
field id="Field01" xsi:type="AttributeEnum">
values>
value>
code>1/code>
/value>
value>
code>2/code>
/value>
value>
code>3/code>
/value>
value>
code>4/code>
/value>
/values>
sql>field01/sql>
default_value />
is_null_allowed>false/is_null_allowed>
/field>
Field 01 = 2
Field 02 = 4
Field 03 = 1
Field MAX =4
Is there some function that computes this automaticly?
Thank you for response.
You'd need to hook into "OnInsert" and/or "OnUpdate" methods to compute this; and ideally make your field max read only as well.
Thank you for pointing me in right direction. I know I couln't avoid these forever...
So I've been successfull in making field "max" read only but im struggling on that max function. I've tried in php sandbox this:
?php
{
$x=1;
$y=0;
$z=2;
$largest=max($x,$y,$z);
$c=$largest;
echo "$c";
}
?>
and it goes pretty well. But when I try to modify it in method I dont know what syntax I have wrong. Toolkit is at this point useless to me.
Also I've changed type of Field to AttributeDecimal because during instalation it was writing some error.
public function Maximumofthree()
{
parent::OnInsert();
$x->Get('Field1');
$y->Get('Field2');
$z->Get('Field3');
$c = max($x,$y,$z);
$this->Set('FieldMax',$c->Format(AttributeDecimal::GetInternalFormat()));
}
Any suggestion what to fix?
Last edit: razsalgul1635 2023-07-27
Might be best to share the entire snippet.
Also, is the formatting really needed?
Plus, your
$x->Get('Field1')
etc seem wrong.$this->Get('Field1')
is more likely.Okey
Field 1:
field id="Field1" xsi:type="AttributeDecimal">
sql>field1/sql>
default_value>0/default_value>
is_null_allowed>false/is_null_allowed>
digits>6/digits>
decimals>2/decimals>
/field>
Field 2:
field id="Field 2" xsi:type="AttributeDecimal">
sql>field2/sql>
default_value>0/default_value>
is_null_allowed>false/is_null_allowed>
digits>6/digits>
decimals>2/decimals>
/field>
Field 3:
field id="Field 3" xsi:type="AttributeDecimal">
sql>field3/sql>
default_value>0/default_value>
is_null_allowed>false/is_null_allowed>
digits>6/digits>
decimals>2/decimals>
/field>
Field Max:
field id="Field Max" xsi:type="AttributeDecimal">
sql>fieldmax/sql>
default_value>0/default_value>
is_null_allowed>false/is_null_allowed>
digits>6/digits>
decimals>2/decimals>
/field>
Method:
method id="Maximumofthree" _delta="define">
comment/>
static>false/static>
access>public/access>
code>
<![CDATA
public function Maximumofthree()
{
parent::OnInsert();
$x = new Decimal($this->Get('Field1'));
$y = new Decimal($this->Get('Field2'));
$z = new decimal($this->Get('Field3'));
$c = max($x,$y,$z);
$this->Set('FieldMax',$c->Format(AttributeDecimal::GetInternalFormat()));
}
]>
/code>
/method>
Well I dont know if formating is needed. I thought it didnt work when it was diffrent object type so I made all one same type it would be fixed.
Edit: I've modified lines in public function as you wrote earlier.
Last edit: razsalgul1635 2023-07-27
Why not keep it much more simple?
.
Yeah I've also tried this and wasnt working aswell. Also Ive tried replacing $this->Set('FieldMax',$c);
with
$this->Set('FieldMax',5);
and it didnt even set field to "5" which was odd.
Last edit: razsalgul1635 2023-07-28
Okey dunno what happened today, but it miraculously started working today...