I have a button that should update a boolean field to true
if certain conditions are met.
I want to do my validation in the JavaScript that fires on button click instead of letting the system run validation rules after the field has been set and then rolling back. My reasoning is justified by the annoyance of not receiving validation errors after using window.location.reload()
utilizing JavaScript.
Can someone tell me specifically why I'd be receiving an undefined error for the custom field that I'm querying against a substring below?
Current_Project_Phase__c
is a text field.
{!REQUIRESCRIPT("/soap/ajax/25.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var currentProjectPhase = {!project_cloud__Project__c.Current_Project_Phase__c};
if (currentProjectPhase !== undefined)
{
if (currentProjectPhase.indexOf("Implementation") !== -1)
{
var projectUpdate = new sforce.SObject("project_cloud__Project__c");
projectUpdate.Id="{!project_cloud__Project__c.Id}";
projectUpdate.Submit_for_Change_Assessment__c = true;
if(projectUpdate != null)
{
try
{
sforce.connection.update([projectUpdate]);
window.location.reload();
}
catch(e)
{
alert("Error : " + e);
}
}
}
else
{
alert("You are currently not in the Implementation stage, change can not be triggered.");
}
}
else
{
alert("Current Project Phase undefined.");
}
The error I'm getting is shown below, FYI "Triage" is the value that's currently contained in the field Current_Project_Phase__c: