If-Else Not working

If-Else Not working


Hello,

I'm having a problem with my script. Here is what I'm trying to do:

1. Copy a response to a resource field to the description when the ticket is submitted
2. If the requester entered information in the description, I want it to appear under a section called "user comments" in the new description
3. If the requester left the description blank, I only want the resource field copied to the new description (no "user comments")
4. I only want information copied once when the ticket is submitted

My script is not working. It adds a "user comments" section regardless of whether or not the old description was blank. Again, I only want "user comments" to appear if the description is NOT blank.

I've attached a screenshot of the result. Below is my script. Would appreciate any advice!


//Capture anything the requester added to the Description//

var old_description_content=$CS.getDescription();

//Capture the requester's response to the File or Folder Restore pick list resource field//
var file_or_folder_resource_field =$CS.getText(" RES_301_QUS_606");

//If the requester left the description blank, just copy the File or Folder information//
if (old_description_content === undefined)
{
var new_description_content= '<b>Action requested</b>' + "<BR>" + file_or_folder_resource_field;
}

//Otherwise (the requester entered information in the description), append their input under "User comments"//
else
{
var new_description_content= '<b>Action requested</b>' + "<BR>" + file_or_folder_resource_field + "<BR><BR>" + '<b>User comments</b>' + "<BR>" + old_description_content;
}

//Unrelated to the conditions above: If the ticket is being submitted, only copy the information once//

if ($CS.isFormSubmit())
  $CS.setDescription(new_description_content);

                  New to ADSelfService Plus?