0

Need optimize this script

let s1 := if Status = 1 then 1 else 0 end;
let s2 := if Status = 2 then 2 else 0 end;
let s3 := if Status = 3 then 3 else 0 end;
if s1 then
    let reply := dialog(" 🟢 Audit To History", " This Audit was Completed and will be archived and removed from Events", ["Confirmed", "No Confirmed"]);
    if reply = "Confirmed" then
        let me := this;
        let newR := (create 'History Completed');
        newR.('Events Audited' := me);
        newR.('Audit No' := me.'Audit Code');
        newR.('Project Audited' := me.'Projects_>'.'Project Name');
        newR.(Appointment := me.Appointment);
        newR.text(Status := me.text(Status));
        newR.(Auditor := me.'Auditor_>'.('First Name' + " " + 'Last Name'));
        newR.(Audited := me.'To Audit_>'.('First Name' + " " + 'Last Name'));
        alert(" Record Archived")
    end
else
    if s2 then
        let reply := dialog(" 🔴 M A J O R - Non Conformities", "This Audit was not compliant. Therefore, major non-conformities will be reviewed within 14 days.", ["Confirmed", "No Confirmed"]);
        if reply = "Confirmed" then
            let today := Today + 14;
            let newRec := duplicate(this);
            openRecord(newRec);
            newRec.('Audit Code' := null);
            newRec.(Status := null);
            newRec.(From := null);
            newRec.(Appointment := null);
            newRec.('Plan within' := 14);
            newRec.('Re Schedule Date' := today);
            let me := this;
            newRec.('Audit Code' := me.'Audit Code' + "_" + "x1");
            sleep(1500);
            openRecord(newRec)
        end
    else
        if s3 then
            let reply := dialog(" 🟠 M I N O R - Non Conformities", "This Audit was not compliant. Therefore, minor non-conformities will be reviewed within 7 days.", ["Confirmed", "No Confirmed"]);
            if reply = "Confirmed" then
                let today := Today + 7;
                let newRec := duplicate(this);
                openRecord(newRec);
                newRec.('Audit Code' := null);
                newRec.(Status := null);
                newRec.(From := null);
                newRec.(Appointment := null);
                newRec.('Plan within' := 7);
                newRec.('Re Schedule Date' := today);
                let me := this;
                newRec.('Audit Code' := me.'Audit Code' + "_" + "x1");
                sleep(1000);
                openRecord(newRec)
            end
        end
    end
end

Hi. There are some way to optimize these script.

Is on Trigger After Update on Choice Field

Appreciate.

2 Antworten

null
    • UweG
    • vor 8 Monaten
    • Gemeldet - anzeigen

    1. Use 1 variable instead of 2 variables
    2. Use a switch...case instead of if...then...else.
    switch...case are faster than if...then...else, maybe not in this example.

    let vStatus := number(Status); [If Status is a choice-field]
    switch vStatus do:
    case 1:
    (....)
    case 2:
    (...)
    case 2:
    (...)
    default:
    (whatever)
    end

      • Rafael_Sanchis
      • vor 8 Monaten
      • Gemeldet - anzeigen

       

      Hi Uwe Thanks The If status 2 and If status 3 are diferent. 

      Mayor non conformoties have New Audit 14 days next

      Minor non conformities have New Audit 7 Day next.