I'm receiving JSON from a 3rd party and need to parse quantity conditionally... Depending on the type of usage of the line item, "ReplacementCount" or "ServiceCount" will need to become "quantity", and delete or ignore the other. THere's no case where both 'lineitemfieldname' will be > 0, it will always be one or the other.
I'm making it to my first if statement, but never into the second... I am pretty certain that I'm handling the if statement for the JSON object/value incorrectly, but am not sure how to resolve.
Here's my sample JSON:
{"recordtype":"salesorder","item":
[{"InventoryManagementKey":"20001","InvoiceDay":"9/10/2015","ReplacementAmount":0.0000,"ReplacementCount":500,"ServiceAmount":0.0000,"ServiceCount":0}]}
Here's the fragment of server-side script handling the JSON:
for(var lineitemfieldname in lineitemobject)
{
var lineitemfieldvalue = lineitemobject[lineitemfieldname];
if(lineitemfieldname == 'ServiceCount' && lineitemfieldvalue != 0)
{
if(lineitemfieldname == 'InventoryManagementKey')
{
lineitemfieldname = 'item';
}
if(lineitemfieldname == 'ServiceCount')
{
lineitemfieldname = 'quantity';
}
delete 'ServiceAmount';
delete 'ReplacementAmount';
delete 'ReplacementCount';
delete 'invoiceDay';
record.setCurrentLineItemValue('item',lineitemfieldname,lineitemfieldvalue);
}
}
I was able to resolve this thanks to rajuGT's guidance. For anyone who stumbles upon this, here's a summary of my resolution:
This will update your json based on "ReplacementAmount"
Here only lineitemobject JavaScript object value changes, not the JSON string.
Validating the JSON Schema Draft-07, JSON now supports the
if...then...else
keywords for conditional data representation.