Use null as IF Statement Criteria


Hi All,

I have an afterSubmit UE script that is to run on only when the ‘created from’ is not null. The script logging shows the value for the ‘created from’ field as below:


I have been using the following code to simply test to ensure I am able to log when the criteria is met, but I have tried many renditions and it is not working:


if (data.createdFrom == null) {
log.debug({ title: 'test' });


However, I also am logging the ‘created from: type’ and that returns an empty value (instead of null) – see below for the exact log syntax:



When I update the above code snippet to the below, it works just fine:


if (data.createdFromType == "") {
log.debug({ title: 'test' });


I know there is a difference between empty and null, but I cannot get this to work when the value of a field is null.

Any suggestions would be helpful! Thank you!


Rookie Asked on May 18, 2021 in SuiteScript.
Add Comment
1 Answer(s)
Best answer

Ignore the problem, use truthiness.

if (!data.createdFromType) {
  log.debug({ title: "test" });
Advanced Answered on May 18, 2021.

We will end up having to go two layers deep, which is why I need to resolve the null issue. I can access the “ created from : type” but I am not able to access “ created from : created from : type”.

on May 18, 2021.

Same answer, truthiness can be used to filter out a wide range of undersirable values. If you are using suitescript 2.1, then Optional chaining is an option.

on May 18, 2021.

Thank you! This does seem to be working.

on May 19, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor