Hi
I followed the example Server Example – Inline Script
When I validate the field “quantity”, how can I retrieve the value of other fields such as “instructions”.
I tried
record.instructions in groovy
record.get("record.instructions ") in Java
record.get("record.instructions ") in Javascript
But none of them were work.
In other words, how to refer to other field values when my validation involves two fields.
Many thanks
<DataSource ID="inlineScript_orderForm" serverType="sql">
<fields>
<field name="orderItem" type="sequence" primaryKey="true"/>
<field name="itemId" foreignKey="StockItem.id"/>
<field name="quantity" type="integer">
<validators>
<validator type="serverCustom">
<serverCondition language="groovy"><![CDATA[
value < dataSources.StockItem.fetchById(record.itemId).quantity
]]></serverCondition>
<!-- serverCondition language="java"><![CDATA[
DataSource ds = (DataSource) dataSources.get("StockItem");
Map rec = ds.fetchById(record.get("itemId"));
Integer quantity = (Integer) rec.get("quantity");
return value < quantity;
]]></serverCondition -->
<!-- serverCondition language="javascript"><![CDATA[
value < dataSources.get("StockItem").fetchById(record.get("itemId")).get("quantity")
]]></serverCondition -->
<errorMessage>Not enough in stock</errorMessage>
</validator>
</validators>
</field>
<field name="instructions" type="text"/>
</fields>
</DataSource>
I followed the example Server Example – Inline Script
When I validate the field “quantity”, how can I retrieve the value of other fields such as “instructions”.
I tried
record.instructions in groovy
record.get("record.instructions ") in Java
record.get("record.instructions ") in Javascript
But none of them were work.
In other words, how to refer to other field values when my validation involves two fields.
Many thanks
<DataSource ID="inlineScript_orderForm" serverType="sql">
<fields>
<field name="orderItem" type="sequence" primaryKey="true"/>
<field name="itemId" foreignKey="StockItem.id"/>
<field name="quantity" type="integer">
<validators>
<validator type="serverCustom">
<serverCondition language="groovy"><![CDATA[
value < dataSources.StockItem.fetchById(record.itemId).quantity
]]></serverCondition>
<!-- serverCondition language="java"><![CDATA[
DataSource ds = (DataSource) dataSources.get("StockItem");
Map rec = ds.fetchById(record.get("itemId"));
Integer quantity = (Integer) rec.get("quantity");
return value < quantity;
]]></serverCondition -->
<!-- serverCondition language="javascript"><![CDATA[
value < dataSources.get("StockItem").fetchById(record.get("itemId")).get("quantity")
]]></serverCondition -->
<errorMessage>Not enough in stock</errorMessage>
</validator>
</validators>
</field>
<field name="instructions" type="text"/>
</fields>
</DataSource>
Comment