Skip to main content

Trying to figure out how to create a new meter reading through the API.
I gather this needs to be done through item_installed and meter_reading_xref.

My first attempt was to use bo_search_keys to specify the meter_id, but this ends up finding and updating the last meter reading, which is undesirable. This makes sense in hindsight.

Attempt 1:

<root>
<session email="" alias="">
<state bc_name="item_installed">
<action name="data">
<main>
<row>
<item_id>556867</item_id>
</row>
</main>
<meter_reading_xref use_retrieve_limit="true">
<row>
<curr_reading>18</curr_reading>
<bo_search_keys>
<item>
<name>item_id</name>
<value>556867</value>
</item>
<item>
<name>meter_id</name>
<value>1</value>
</item>
</bo_search_keys>
</row>
<row>
<curr_reading>19</curr_reading>
<bo_search_keys>
<item>
<name>item_id</name>
<value>556867</value>
</item>
<item>
<name>meter_id</name>
<value>2</value>
</item>
</bo_search_keys>
</row>
</meter_reading_xref>
</action>
</state>
</session>
</root>

Attempt 2 was to just specify the meter readings as rows without search keys.

<root>
<session email="" alias="">
<state bc_name="item_installed">
<action name="data">
<main>
<row>
<item_id>556867</item_id>
</row>
</main>
<meter_reading_xref use_retrieve_limit="true">
<row>
<curr_reading>18</curr_reading>
<meter_id>1</meter_id>
</row>
<row>
<curr_reading>19</curr_reading>
<meter_id>2</meter_id>
</row>
</meter_reading_xref>
</action>
</state>
</session>
</root>

Weirdly, this fails, but if I specify readings that already match an existing reading, it fails because “A row with the identical values for Reading, Reading Date,Source,  Replacement and Credit data already exists for the 'JobInvoicingTest_STD' item and 'Total B&W' Meter Type.”

If I update the curr_reading to not be the same as an existing value, then I just get:
 

succeeded:false

Error Message:: Execute Macro 'Save' failed.
reason: <root><BOName></BOName><MessageID></MessageID><MessageAsteaCode>A2GEN017</MessageAsteaCode><ElementName></ElementName><Message>System error occurred. Contact your System or Database Administrator.
Date: 2024-06-10 9:21:37 PM
Event: 65535
Ref #: b590b1eb-8845-45ec-8819-b00d88ebce30
Date: 2024-06-10 11:21:37 AM UTC</Message><Row></Row><Code>AsteaException</Code></root>

I suspect I’m close, but I need some help. I want to be able to submit meter readings from an external application. These should be able to be submitted with a reference ideally, like the order id for meters logged through a service order, and a new reading should be created even if the value is the same as an existing reading.

Never mind! Figured it out. You need the plan_id too.

 

<root>
<session alias="" email="">
<state bc_name="item_installed">
<action name="declare">
<attribute value="" name="itemID" out_var="" in_var="" dtype="number"/>
<attribute value="" name="meterId0" out_var="" in_var="" dtype="number"/>
<attribute value="" name="planId0" out_var="" in_var="" dtype="number"/>
<attribute value="" name="meterId1" out_var="" in_var="" dtype="number"/>
<attribute value="" name="planId1" out_var="" in_var="" dtype="number"/>
</action>
<action name="getdescrtableex">
<attribute search_criteria="bpart_id='IMC2000' and serial_no='JobInvoicingTest_STD'" element_name="item_id" table_name="item" out_var="itemID" in_var=""/>
</action>
<action name="getdescrtableex">
<attribute search_criteria="bpart_id='IMC2000' and descr='Total B&amp;W' and is_active='Y'" element_name="meter_id" table_name="meter_bpart_xref" out_var="meterId0" in_var=""/>
</action>
<action name="getdescrtableex">
<attribute search_criteria="bpart_id='IMC2000' and descr='Total B&amp;W' and is_active='Y'" element_name="unique_plan_id" table_name="meter_bpart_xref" out_var="planId0" in_var=""/>
</action>
<action name="getdescrtableex">
<attribute search_criteria="bpart_id='IMC2000' and descr='Total Colour' and is_active='Y'" element_name="meter_id" table_name="meter_bpart_xref" out_var="meterId1" in_var=""/>
</action>
<action name="getdescrtableex">
<attribute search_criteria="bpart_id='IMC2000' and descr='Total Colour' and is_active='Y'" element_name="unique_plan_id" table_name="meter_bpart_xref" out_var="planId1" in_var=""/>
</action>
<action name="data">
<main>
<row>
<item_id dtype="int" in_var="itemID" out_var="">in_var</item_id>
</row>
</main>
<meter_reading_xref>
<row>
<cc_unique_plan_id dtype="int" in_var="planId0" out_var="">in_var</cc_unique_plan_id>
<curr_reading>52</curr_reading>
<reading_date>2024-06-10</reading_date>
<source>1</source>
<meter_id dtype="int" in_var="meterId0" out_var="">in_var</meter_id>
</row>
<row>
<cc_unique_plan_id dtype="int" in_var="planId1" out_var="">in_var</cc_unique_plan_id>
<curr_reading>62</curr_reading>
<reading_date>2024-06-10</reading_date>
<source>1</source>
<meter_id dtype="int" in_var="meterId1" out_var="">in_var</meter_id>
</row>
</meter_reading_xref>
</action>
</state>
</session>
</root>

 


Reply