Issues with an empty value

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!

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

Hi E1cid,

This is the flow:

The incoming data out of the debug node (graduates) looks like this:

image

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.

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.

Thanks Colin.
I'll give that a try. :slight_smile:

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

E1cid,

Yup, that looks complicated to read.