Problem with If script

Viewing 4 reply threads
  • Author
    Posts
  • July 8, 2020 at 6:34 AM #41210

    Victor Warner
    Participant

    Two issues:

    First issue: Finding the error in the script

    I am having an issue with the following script:

    var address_field_id = 'fld-1f639ae503fe419b8473b02ea17d4ac4';
    var address_field = record.getFieldValue('fld-1f639ae503fe419b8473b02ea17d4ac4');
    
    result = '';
    
    if (address_field=="newly identified - work address") {
    
    	result = record.getFieldValue('fld-943ab25fd0de42e7b8d1e5487c6a358b');
    	
    
    } else if (address_field=="already identified - work address") {
    
    	
    	result = record.getFieldValue('fld-11915a3f275a4938949714a664dc40bf');
     
     } else (address_field=="newly identified - personal address") {
    
    	
    	result = record.getFieldValue('fld-0e624f31b7af41b18fcb0262a7ec2a0d');
    
     }
    
    result;

    I am getting an error message in the script editor:

    Address chooser: SyntaxError: Unexpected token ‘{‘. Parse error., line:13

    Line 18 being the final else statement (“} else (address_field==”newly identified – personal address”) {“).

    I cannot see the error, although I am sure it is a typo on my part.

    Using a pick list as a basis to use data from other fields

    The aim of the above script is as follows:

    1. I field has a pick list
    2. The script field (using the code) will test which of the items in the pick list have been chosen and then get the value of another field in the database.

    The complete database is attached (although a simplified version of what I want to do).

    Is the script (as done or as corrected) the best way of this?

    Any help with this would be gratefully received.

    Attachments:
    You must be logged in to view attached files.
    July 8, 2020 at 8:30 AM #41213

    Daniel Leu
    Participant

    Re 1: Either use else if (condition) {} or else {}. You can’t use a condition with an else statement.

    July 8, 2020 at 9:11 AM #41216

    Victor Warner
    Participant

    Daniel,

    Thank you for the response. Only having else if statements stops the error message.

    But I am not getting any output at all. When I tick any of the items in the pick list field – nothing appears – I would be grateful to identify what I am doing wrong or missing.

    July 8, 2020 at 3:04 PM #41220

    Daniel Leu
    Participant

    Hi Victor,

    I noticed a few things:

    1. One of the pick list entries stated by a whitespace. You should remove that
    2. In your script, all branches need to be else if
    3. The address field selector should not be a checkmark, but a unique selector such as Single Value Popover

    With these changes, the script works for me.

    Here is the code I’m using:

    var address_field_id = 'fld-1f639ae503fe419b8473b02ea17d4ac4';
    var address_field = record.getFieldValue(address_field_id);
    
    let result = '';
    
    if (address_field=="newly identified - work address") {
    	result = record.getFieldValue('fld-943ab25fd0de42e7b8d1e5487c6a358b');
    } else if (address_field=="already identified - work address") {
    	result = record.getFieldValue('fld-11915a3f275a4938949714a664dc40bf');
    } else if (address_field=="newly identified - personal address") {
    	result = record.getFieldValue('fld-0e624f31b7af41b18fcb0262a7ec2a0d');
    }
    
    result;

    Please note that sometimes you need to press Recalculate formulas to get the record’s fields updated.

    July 10, 2020 at 7:32 AM #41245

    Victor Warner
    Participant

    Daniel,

    Thank you very much for the further help. Particularly about learning about the use of else if and the need to use the Single Value Popover.

Viewing 4 reply threads

You must be logged in to reply to this topic.