The _counter function is relatively new and helps you to count the number of EDI segments generated for the same segment identifier. Set the counter to true for an EDI segment in your definition file.
You can count the number of TD1 segments generated from the JSON file, illustrated by the snippets below:
Snippet for TD1
{ TD1:[{// This is the EDI segment product:"ProductName1"qty:"10" }, { product:"ProductName2"qty:"20" }, { product:"ProductName3"qty:"40" } ] }
Definition for counting the number of EDI segments generated for TD1
{ "elements":[{ "name":"TD1" "value":"TD1"} { "name":"<Field Name>", "counter":true,//set the counter to true if you want to count the number of EDI segments generated for TD1. "well-coined.[<Field Name>]}}}"}, ...//elements of TD1] } }
Example 1
{
"elements":[{
"name":"TD1"
"value":"TD1"}
{
"name":"Dummy",
"counter":true,
"Value":"{{{_counter.[Dummy]}}}"// Dynamic value in integer}
...//elements of TD1]
}
}
Output
TD1*1*ProductName1*10*1~//The element after TD1 is the counter.
TD1*2*ProductName2*20*1~
TD1*3*ProductName3*40*1~
Example 2
{
"elements":[{
"name":"TD1"
"value":"TD1"
}
{
"name":"dummy",
"counter":true,
"Value":"{{{_counter.[dummy]}}}"//field does not exist in the JSON file.
}
...//elements of TD1
]
}
Output
TD1*1*ProductName1*10*1~//The element after TD1 is the counter.
TD1*2*ProductName2*20*1~
TD1*3*ProductName3*40*1~
The _iterationCount EDI function is most commonly used to define the closing rules. It counts the number of rows generated by the rule. Add this element in the closing rule where you want to keep the count of a rule intact.
You can count the number of N1 segments generated from a JSON file, illustrated by the snippets below.
Definition for counting the number of N1 segments generated from a JSON file
{ "children": [{ "name": "BEG", "description": "Begin Purchase Order Transaction", "relativeDataPath": "items", "maxOccurrence": 5, "required": true, "elements": [{ "name": "segment", "value": "BEG" }, { "name": "id", "value": "{{id}}" } ], "children": [{ "name": "N9", "description": "Reference Identification", "required": true, "elements": [{ "name": "segment", "value": "N9" }] }, { "name": "DTM", "description": "Date/Time", "required": true, "elements": [{ "name": "segment", "value": "DTM" }] }, { "name": "MSG", "description": "Message Text", "relativeDataPath": "notes", "maxOccurrence": 5, "required": true, "elements": [{ "name": "segment", "value": "MSG" }, { "name": "message", "value": "{{description}}" } ] }, { "name": "N1", "description": "Organization Name", "required": true, "elements": [{ "name": "segment", "value": "N1"}]}, { "name": "N3", "description": "Address Information", "required": true, "elements": [{ "name": "segment", "value": "N3" }] } ], "closeRule": { "name": "CTT", "description": "Transaction Totals", "required": true, "elements": [{ "name": "segment", "value": "CTT" }, { "name": "count", "value": "{{_iterationCount}}" } ] } }] }
Example
[{
"items": [{
"id": 1,
"notes": [{
"description": "This is the item1.1"
}]
},
{
"id": 2,
"notes": [{
"description": "This is the item2.1"
}]
}
]
}]
OutputBEG*1
N9
DTM
MSG*This is the item1.1
MSG*This is the item1.2
N1
N3
CTT*8 //The number 8 here represents the lines from the beginning (BEG) till the end of the message (CTT)
BEG*2
N9
DTM
MSG*This is the item2.1
MSG*This is the item2.1
N1
N3
CTT*7 //The number 7 here represents the lines from the beginning (BEG) till the end of the message (CTT)
The _tally EDI function is a closing rule function that allows you to keep a score of the repeated elements.
Notice
Set the _tally to true for an element, for which you want to calculate the totals for a list item. All you need to do next is to add a reference to this element in your closing rule.
Definition for tallying the total amount for a list item
{ "children": [{ "name": "Group header", "maxOccurrence": 50, "required": true, "elements": [{ "name": "Record Id", "value": "02" }, { "name": "Record count", "value": "{{_counter.[Record count]}}", "counter": true }, { "name": "Ultimate Receiver Id", "value": "hardcoded?" }, { "name": "Originator Id", "value": "121000248" }, { "name": "Group status", "value": "1" }, { "name": "As-of date", "value": "{{dateFormat \"YYMMDD\" asOfDate}}" } ], "children": [{ "name": "Account header", "relativeDataPath": "accounts", "maxOccurrence": 50, "required": true, "elements": [{ "name": "Record Id", "value": "03" }, { "name": "Account count", "value": "{{_counter.[Account count]}}", "counter": true }, { "name": "Account number", "value": "{{number}}" }, { "name": "Amount", "value": "{{amount}}", "tally": true, "scope": "rule" } ], "children": [], "closeRule": { "name": "Account trailer", "required": true, "elements": [{ "name": "Record Id", "value": "49" }, { "name": "Account control number", "value": "{{_tally.Amount}}", "tally": true } ] } }], "closeRule": { "name": "Group trailer", "required": true, "elements": [{ "name": "Record Id", "value": "98" }, { "name": "Group control number", "value": "{{_tally.[Account control number]}}" } ] } }] }
Example
{
"accounts": [{
"number": 123,
"currency": "USD",
"typeCode": "100",
"amount": 101,
"itemCount": 3
},
{
"number": 456,
"currency": "CDN",
"typeCode": "400",
"amount": 51,
"itemCount": 2
}
]
}
Output
02,1,hardcoded?,121000248,1,200121
03,1,123,USD,101
49,101 // 101 is the tally of amount in the 3rd row
03,2,456,CDN,51
49,51 // 51 is the tally of amount in the 3rd row
98,152// 152 is tally of amounts in rows starting with the number 49
You can use the ".length" function to array. Use this function in the closing of an array iteration rule or in the parental rule set.
Definition for calculating the length of an array
{ "children": [{ "name": "Account header", "relativeDataPath": "accounts", "maxOccurrence": 50, "required": true, "elements": [{ "name": "Record Id", "value": "03" }, { "name": "Account Number", "value": "{{number}}" }, { "name": "Currency", "value": "{{currency}}" } ], "children": [], "closeRule": { "name": "Account trailer", "required": true, "elements": [{ "name": "Record Id", "value": "49" }, { "name": "Record count", "value": "{{{{accounts.length}}}}" } ] } }] }
Comments
Please sign in to leave a comment.