What's wrong with this code? :)

Avatar

Avatar

ellis355

Avatar

ellis355

ellis355

23-06-2015

Hi Guys - would appreciate a little help here, I think I'm close but...

I am trying to write javascript to check whether several fields are null. Basically if ANY of the fields are populated then FinanceNotes should = "filled", if they are ALL null then it should be "empty".

The code I have so far is below however I am unsure what the correct syntax is to add all of the fields (FinanceImpact7, HealthSafetyImpact7 etc) - is it && or || etc?

if (ImpactsTable.Row1.FinanceImpact7.rawValue == null && ImpactsTable.Row2.HealthSafetyImpact7.rawValue == null && ImpactsTable.Row2.OpsBusinessImpact7.rawValue == null)

{

Subform2.ImpactsTable.Row1.FinanceNotes.rawValue = "empty";

}

else

{

Subform2.ImpactsTable.Row1.FinanceNotes.rawValue = "filled";

}



Cheers!!

Ellis

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

radzmar

MVP

Avatar

radzmar

MVP

radzmar
MVP

24-06-2015

You're using wrong SOM expressions, because you're pointing to row2, that does not contain the desired field.

Subform2.ImpactsTable.Row1.FinanceNotes.rawValue = ImpactsTable.Row1.FinanceImpact7.isNull && ImpactsTable.Row2.HealthSafetyImpact7.isNull && ImpactsTable.Row2.OpsBusinessImpact7.isNull && ImpactsTable.Row2.OpsCustomersImpact7.isNull && ImpactsTable.Row2.OpsEmployeesImpact7.isNull && ImpactsTable.Row2.ReputationHeader7.isNull && ImpactsTable.Row2.ReputationStakeholders7.isNull ? "empty" : "filled";

Change it into:


ImpactsTable.Row1.FinanceNotes.rawValue = ImpactsTable.Row1.FinanceImpact7.isNull && ImpactsTable.Row2.HealthSafetyImpact7.isNull && ImpactsTable.Row3.OpsBusinessImpact7.isNull && ImpactsTable.Row4.OpsCustomersImpact7.isNull && ImpactsTable.Row5.OpsEmployeesImpact7.isNull && ImpactsTable.Row6.ReputationHeader7.isNull && ImpactsTable.Row7.ReputationStakeholders7.isNull ? "empty" : "filled";


Answers (4)

Answers (4)

Avatar

Avatar

ellis355

Avatar

ellis355

ellis355

29-06-2015

Thanks radzmar!

Homer-simpson-quotes-doh-i11.jpg

Avatar

Avatar

ellis355

Avatar

ellis355

ellis355

24-06-2015

Thanks both for your ideas

Radzmar : I amended your code by adding some additional fields ( I have 7 in total ), I have used exactly the same syntax as your example yet it only seems to recognize that the first 2 fields are not null? Also the "empty" result does not seem to work?

Here is my amended code:

Subform2.ImpactsTable.Row1.FinanceNotes.rawValue = ImpactsTable.Row1.FinanceImpact7.isNull && ImpactsTable.Row2.HealthSafetyImpact7.isNull && ImpactsTable.Row2.OpsBusinessImpact7.isNull && ImpactsTable.Row2.OpsCustomersImpact7.isNull && ImpactsTable.Row2.OpsEmployeesImpact7.isNull && ImpactsTable.Row2.ReputationHeader7.isNull && ImpactsTable.Row2.ReputationStakeholders7.isNull ? "empty" : "filled";

And here is the pdf if it's easier?

https://www.dropbox.com/s/hrljvjyda8pd5ei/211%20For%20Forum.pdf?dl=0

Many many thanks !

Ellis

Avatar

Avatar

radzmar

MVP

Avatar

radzmar

MVP

radzmar
MVP

23-06-2015

To test for null value you should use the operator === instead of ==

or you use the build-in method isNull.

Subform2.ImpactsTable.Row1.FinanceNotes.rawValue = ImpactsTable.Row1.FinanceImpact7.isNull && ImpactsTable.Row2.HealthSafetyImpact7.isNull && ImpactsTable.Row2.OpsBusinessImpact7.isNull ? "empty" : "filled";

Avatar

Avatar

Magus069

MVP

Avatar

Magus069

MVP

Magus069
MVP

23-06-2015

Hi there,

the way you're code is working is, if each fields are null, give FinanceNotes "empty" value

if 1 field is different than null, give FinanceNotes "filled" value

Make sure that your syntax is good and each field names are well spelled, use the debugger to see if any error occurs and use the try catch statement to see in details the error..

Handling JavaScript Exceptions

I can see that in your if statement you specify ImpactsTable directly but in your code within the if clause is starting at Subform2.ImpactsTable.. make sure you use the right reference_syntax!

Hope this help!