TartanTaurus
asked on
Javascript if statement if a field is not null
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
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;
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think your problem lies somewhere else ...
Instead of doing the conditional test, replace the comand with:
alert(oppoRecord.oppo_admi ssiondate) ;
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?
Instead of doing the conditional test, replace the comand with:
alert(oppoRecord.oppo_admi
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?
Is oppoRecord null?
if ( oppoRecord && oppoRecord.oppo_admissiond ate ) {
// You have an actual value with which to work
}
if ( oppoRecord && oppoRecord.oppo_admissiond
// You have an actual value with which to work
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)?
}
ASKER
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!
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!
ASKER
Accepting the syntax as != '' as the answer I was looking for. Thanks
ASKER
if (oppoRecord.oppo_admission
if (oppoRecord.oppo_admission
if (oppoRecord.oppo_admission
None work the line below still fires
{
Values("oppo_customerref")
}