Solved

Javascript if statement if a field is not null

Posted on 2009-03-31
9
4,929 Views
Last Modified: 2012-05-06
Hi,

This is probably very simple or my logic is possibly incorrect! What I want to do is to say:

If a field is not Null (contains any data) then fire the operation.

The line i need help with is * if (oppoRecord.oppo_date!=="") *

Clearly that's not correct I've looked into possibly using the length property to say if length > 0 then do operation but again my coding lets me down!

Thanks
function UpdateRecord()
 

{
 

var oppoRecord = eWare.FindRecord("Opportunity",WhereClause); 
 

if (oppoRecord.oppo_date!=="")

{

Values("oppo_customerref")=oppoRecord.oppo_opportunityid; 

}
 

}

Open in new window

0
Comment
Question by:TartanTaurus
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 11

Assisted Solution

by:rafael_acc
rafael_acc earned 40 total points
ID: 24031747
it's "!=" not "!==!"

In javascript, if my memory is not failing me, you can also use i (opoRecord.opo_date != null)
0
 
LVL 1

Author Comment

by:TartanTaurus
ID: 24031928
I've tried the following combinations:

if (oppoRecord.oppo_admissiondate !='')
if (oppoRecord.oppo_admissiondate !="")
if (oppoRecord.oppo_admissiondate !=null)

None work the line below still fires
{
Values("oppo_customerref")=oppoRecord.oppo_opportunityid;
}
0
 
LVL 11

Expert Comment

by:rafael_acc
ID: 24031982
I think your problem lies somewhere else ...
Instead of doing the conditional test, replace the comand with:

alert(oppoRecord.oppo_admissiondate);

if this object is valid, you should really get either "[object]" in a popup, or the value of the variable at that time. You shouldn't get an error - if you do get an error, what does the error message say?
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24032051
Is oppoRecord null?

if ( oppoRecord && oppoRecord.oppo_admissiondate ) {
  // You have an actual value with which to work
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Assisted Solution

by:Ramanhp
Ramanhp earned 40 total points
ID: 24032478
use this syntax >>> if (oppoRecord.oppo_date != '' )
0
 
LVL 18

Accepted Solution

by:
Morcalavin earned 45 total points
ID: 24032697
It depends on what you mean by 'null' and if you are wanted to do type coercion or not.

var foo = ''; //this is not null, this is an empty string

var foo;  //this is not null, this is undefined

var foo = null;  //this is null
 

var foo = null;

if(foo != '') {

//this code would run.  foo is null, not an empty string

}
 

var foo;

if(foo != '') {

//again, this code runs.  foo is undefined, not an empty string.

}
 

var foo = '';

if(foo != '') {

//this doesn't run.  foo is an empty string.

}
 

var foo;

if(foo != null) {

//this code does NOT run.  != and == do type coercion, so undefined and null are the same

} 
 

var foo;

if(foo !== null) {

//this code runs.  !== and === do NOT do type coercion, so null and undefined are not the same

}
 

var foo = 1

if(foo != true) {

//this code does not run. != and == do type coercion, so 1 and true are the same

}
 

var foo = 1

if(foo !== true) {

//this code does run.  !== and === do NOT do type coercion, so 1 and true are not the same.

}

Open in new window

0
 
LVL 18

Expert Comment

by:Morcalavin
ID: 24032761
Forgot a  few.  Make sure you know exactly what you want to test and the type of object is should be when you test it.

var foo;

if(!foo) {

//runs foo is undefined

}
 

var foo = null;

if(!foo) {

//runs foo is null

}
 

var foo = false;

if(!foo) {

//runs foo is false

}
 

var foo = 0;

if(!foo) {

//runs foo is 0(type coercion!  is this what you REALLY wanted)?

}
 

var foo = '';

if(!foo) {

/runs.  foo is an empty string(type coercion!  is this what you REALLY wanted)?

}

Open in new window

0
 
LVL 1

Author Comment

by:TartanTaurus
ID: 24033425
Ok the syntax if (oppoRecord.oppo_stage !== 'UnderReview') works fine.

The problem clearly lies with the oppo_admissiondate field. This field is part of an active record as the script only serves to "update" an existing record. In the SQL query analyzer the field shows as 'NULL'. That is nothing has ever been entered into it, maybe that's the problem.

It runs ok with all fields that contain text. The line above works fine. I will accept multiple solutions for all who responded as such.

thanks very much!
0
 
LVL 1

Author Closing Comment

by:TartanTaurus
ID: 31564964
Accepting the syntax as != '' as the answer I was looking for. Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now