Help

If statement not working despite no errors

Topic Labels: Scripting extentions
Solved
Jump to Solution
647 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Sarah_Viljoen
6 - Interface Innovator
6 - Interface Innovator

Hi there :slightly_smiling_face: I have a very simple code involving if statements and buttons but it’s not working. I’ll explain further below my code:

 
    let sale = await input.buttonsAsync("Is the vehicle set for another service or will it be sold/scrapped before then?", ["Yes, another service date", "No, will be disposed"]);

    if (sale = "Yes, another service date")
    {
        let plan = await input.buttonsAsync("Is the next service on a date or at a specific mileage?", ["Date", "Mileage"]);

        if (plan = "Date")
        {
            let date1 = await input.textAsync("What is the date of the next service? ( eg: May 1, 2022 )");
            let format_date1 = new Date(date1);
            let format_date2 = new Date(format_date1.setDate(format_date1.getDate()+1));
            let final = format_date2.toISOString()

            let field = table.getField("Next Service (if Date)");

            let confirm = await input.buttonsAsync("Are you sure you want to update the service info as above?", ["Yes, confirm", "No, cancel"]);

            if (confirm = "Yes, confirm")
            {
                table.updateRecordAsync(record.id, {[field.name]: final});
                table.updateRecordAsync(record.id, {[fieldM.name]: Number(mile)});
                table.updateRecordAsync(record.id, {[fieldL.name]: format_date3});
            }

            else if (confirm = "No, cancel")
            {
                output.text("Update cancelled. Do not click 'Run', click the small x near the top right corner to exit.");
            }

        }

        else if (plan = "Mileage")
        {
            let mile1 = await input.textAsync("What mileage is the next service due?");
            let final = Number(mile1);

            let field = table.getField("Next Service (if Mileage)");

            let confirm = await input.buttonsAsync("Are you sure you want to update the service info as above?", ["Yes, confirm", "No, cancel"]);

            if (confirm = "Yes, confirm")
            {
                table.updateRecordAsync(record.id, {[field.name]: final});
                table.updateRecordAsync(record.id, {[fieldM.name]: Number(mile)});
                table.updateRecordAsync(record.id, {[fieldL.name]: format_date3});
            }

            else if (confirm = "No, cancel")
            {
                output.text("Update cancelled. Do not click 'Run', click the small x near the top right corner to exit.");
            }
        }

        
    }


    else if (sale = "No, will be disposed")
    {
         let confirm = await input.buttonsAsync("Are you sure you want to update the service info as above?", ["Yes, confirm", "No, cancel"]);
         
         if (confirm = "Yes, confirm")
            {
                table.updateRecordAsync(record.id, {[fieldM.name]: Number(mile)});
                table.updateRecordAsync(record.id, {[fieldL.name]: format_date3});
            }

            else if (confirm = "No, cancel")
            {
                output.text("Update cancelled. Do not click 'Run', click the small x near the top right corner to exit.");
            }
    }

My code has no errors or anything, but some of my button variables are remaining grey despite being called immediately after in if statements and the if statements are just going in order, not actually according to what button is selected. I have no idea why (my formatting and brackets are correct I think), so could someone please kindly point out anything that could be causing this. I hope I haven’t missed something glaringly obvious. (Sorry if there is a lot of unnecessary coding - I haven’t been doing this for long).

Button variables remaining grey are ‘sale’, ‘plan’, ‘confirm’.

1 Solution

Accepted Solutions
Alexey_Gusev
12 - Earth
12 - Earth

Hi,

that’s usual story (and for me either), mixing up assignment operator ‘=’ with ‘==’ in if statement.

instead of if (plan = "Date"), use if (plan === "Date").

See Solution in Thread

2 Replies 2
Alexey_Gusev
12 - Earth
12 - Earth

Hi,

that’s usual story (and for me either), mixing up assignment operator ‘=’ with ‘==’ in if statement.

instead of if (plan = "Date"), use if (plan === "Date").

Sarah_Viljoen
6 - Interface Innovator
6 - Interface Innovator

Oh okay thank you ! I’ve written a bunch of code using the ‘==’ but this time just didn’t click. Thank you so much :slightly_smiling_face: