ralvez
9 September 2024 18:22
1
I have a template with the following code:
if (
msg.payload['Outcome Status'] == '' ||
msg.payload['Outcome Status'] == null
) { msg.payload['Outcome Status'] = 'SO'}
UPDATE SHRDGMR SET
SHRDGMR_SEQ_NO = {{payload.Degree Sequence}},
SHRDGMR_DEGS_CODE = '{{payload.Outcome Status}}',
SHRDGMR_GRST_CODE = '{{payload.Graduation Status}}',
SHRDGMR_DATA_ORIGIN = 'GradAutomation',
SHRDGMR_USER_ID = USER,
SHRDGMR_GRAD_DATE = TO_DATE('{{{payload.Graduation Date}}}','MM/DD/YYYY'),
SHRDGMR_ACTIVITY_DATE = SYSDATE
WHERE SHRDGMR_PIDM = {{payload.Student PIDM}}
My expectation is that whenever the Outcome Status is an empty string it will set it to 'SO', however, that's not the case.
What am I doing wrong?
Thanks!
E1cid
9 September 2024 18:26
2
ralvez:
I have a template
What do you mean by this?
Is this a dashboard template?
Or a http endpoint?
Hard to say without all the info, what is the value of msg.payload being fed into the script when it fails. Add debug nodes prior to the function.
If I had to guess, msg.payload is non existent where the script runs
ralvez
9 September 2024 18:47
3
Hi E1cid,
This is the flow:
The incoming data out of the debug node (graduates) looks like this:
As you can see the Outcome Status is null. That will make the query to the database fail.
I want to make use that there will be a default value ('SO') if there was not data sent for that item.
Colin
9 September 2024 19:01
4
You can't write JavaScript in a template node. Use a Switch node in front of the template. I think Is Empty
will do what you want.
ralvez
9 September 2024 19:03
5
Thanks Colin.
I'll give that a try.
E1cid
9 September 2024 19:27
6
This also works in a template node (inverted section), but you might be better off doing this all in a function node using template strings
UPDATE SHRDGMR SET
SHRDGMR_SEQ_NO = {{payload.Degree Sequence}},
SHRDGMR_DEGS_CODE = '{{#payload.Outcome Status}}{{.}}{{/payload.Outcome Status}}{{^payload.Outcome Status}}SO{{/payload.Outcome Status}}',
SHRDGMR_GRST_CODE = '{{payload.Graduation Status}}',
SHRDGMR_DATA_ORIGIN = 'GradAutomation',
SHRDGMR_USER_ID = USER,
SHRDGMR_GRAD_DATE = TO_DATE('{{{payload.Graduation Date}}}','MM/DD/YYYY'),
SHRDGMR_ACTIVITY_DATE = SYSDATE
WHERE SHRDGMR_PIDM = {{payload.Student PIDM}}
https://mustache.github.io/mustache.5.html
ralvez
9 September 2024 19:36
7
E1cid,
Yup, that looks complicated to read.