› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › Math Function in Xlate
I need to add code to an existing xlate that checks the value in FT1;4 to see if it’s older than 183 days. The date is being sent as 20130830 in FT1;4.
Does anyone have ideas as to how I can accomplish this? I’m assuming I need to use a math function but I’ve never used one before. Any help would be greatly appreciated!
Best Regards,
Shannon
How about using something like:
lindex $xlateInVals 0 (represents your ft1:4 value)
if {[clock scan [lindex $xlateInVals 0]] > [clock scan “183 days ago”]} {
echo “It is less than 183 days ago”
set xlateOutVals
} else {
echo “It is greater than 183 days ago”
set xlateOutVals
}
Hi Keith! Thanks for your suggestion. I need to suppress any message that is not older than 183 days so would I put the code you provided within the IF statement or does this go in a tcl proc? I’m a little confused on where to place the code exactly. Thanks again for yourh help!
Best Regards,
Shannon
Shannon,
If your objective is to filter the message, I generally would put it into a tps tclproc and use it in the PreXlate location by setting your message disposition to either kill or continue.
If you want to use it in the xlate, I would suggest the preproc location with FT1:4 as your source. Some folks use code snippets here or place this code into xltp tcl procs. I have added a few attachments that may help….
Either way, you may want to think about the FT1 segment can repeat. Are you planning on killing the message if one occurrence is older than 183 days….?
Hope this helps…
Thank you very much! Also, good call on the fact that FT1;4 repeats! I will take that into consideration upon deciding where to place the code. I greatly apprecaite your help!
Best Regards,
Shannon
Hi Keith,
I tried using the code you provided but I’m getting an error. Have you seen this error before?
RUNNING INBOUND TPS IN START MODE
DONE STARTING INBOUND TPS
out is -> 3
xlateInVals=201308301400
xlateInVals=20130830
xlateInVals=40630386
[xlt :xlat:ERR /0: UNNAMED_TID:03/24/2014 09:29:54] [0.0.4] Xlate ‘stjo_dft_cer_6mtn_report_xlate.xlt’ failed: Tcl callout error
if {[clock scan[lindex $xlateInVals 0]] > [clock scan “183 days ago”]}
{echo “It is less than 183 days ago”
set xlateOutVals
echo “It is greaer than 183 days ago”
set xlateOutVals
errorCode: NONE
errorInfo:
bad option “scan20130830”: must be clicks, format, scan, or seconds
while executing
“clock scan[lindex $xlateInVals 0]”
You’re missing a space here:
scan[lindex
It should be:
scan [lindex
Try putting a space after the scan part of the command.
Thank you both! I made the change but now I have a new error:
out is -> 3
xlateInVals=201308301400
xlateInVals=20130830
xlateInVals=40630386
[xlt :xlat:ERR /0: UNNAMED_TID:03/24/2014 10:43:26] [0.0.4] Xlate ‘stjo_dft_cer_6mtn_report_xlate.xlt’ failed: Tcl callout error
if {[clock scan [lindex $xlateInVals 1]] > [clock scan “183 days ago”]}
{echo “It is less than 183 days ago”
set xlateOutVals
echo “It is greaer than 183 days ago”
set xlateOutVals
errorCode: NONE
errorInfo:
wrong # args: no script following “[clock scan [lindex $xlateInVals 1]] > [clock scan “183 days ago”]” argument
while executing
“if {[clock scan [lindex $xlateInVals 1]] > [clock scan “183 days ago”]}”
Move the left curly brace { up to the “if” line preceded by a space; I believe the newline preceding the {echo “It is less than 183 days ago” is causing the problem, i.e:
if {[clock scan [lindex $xlateInVals 1]] > [clock scan “183 days ago”]} {
Thank you! That was exactly the problem. One more question…it looks like the code is translating the date incorrectly. So even though my transaction has 20130630 in FT1;4 the code is stating the transaction is less than 183 days old when it’s actually greater than 183 days old. I’m seeing 3 different values for xlateInVals in the testing tool. Any ideas?
xlateInVals=201308301400
xlateInVals=20130630
xlateInVals=40630386It is less than 183 days ago
multi_dft_cer_out MSH|^~&|SJOCHG|SJO|CHOC|CHOC|201308301400||DFT^P03|796479-1|T|2.3
PID|1||07109824||TEST^MOCK|||||||||||||7100991996
FT1|1|796479-1||20130630|20140324|CHG|40630386^^BASE|||1||||||||||0
Here is a post of an example of killing messages older than 6 hours that I implemented in a trxID proc:
<a href="https://usspvlclovertch2.infor.com/viewtopic.php?t=1562″ class=”bbcode_url”>https://usspvlclovertch2.infor.com/viewtopic.php?t=1562
I imagine my example can be adapted for 183 days since it uses an argument driven proc called oth_chk_time_span written by Jim kosloskey, the source of which is posted here:
<a href="https://usspvlclovertch2.infor.com/viewtopic.php?t=2828″ class=”bbcode_url”>https://usspvlclovertch2.infor.com/viewtopic.php?t=2828
Russ Ross
RussRoss318@gmail.com
I found the issue within my code and it works perfectly now. Thank you all for your help! I greatly appreciate it!
Best Regards,
Shannon