4

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:

Error: Triage is not defined

1 Answer 1

3

Replace:

var currentProjectPhase = {!project_cloud__Project__c.Current_Project_Phase__c};

With:

var currentProjectPhase = "{!project_cloud__Project__c.Current_Project_Phase__c}"; 

Also:

if (currentProjectPhase !== undefined)

will never return false because once you declared 'var currentProjectPhase' it will never be 'undefined'. So replace it with:

if (currentProjectPhase !== '' || currentProjectPhase !== null)
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .