0
Optimize this Code is to large
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' + "_" + 1)
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' + "_" + 1)
end
end
end
end
Copy
Is there a way to optimize this code? S2 and S3 are the same, the difference is that S2 is the next 14 days and S3 is the next 7 days.
The code works but I would like to optimize it, maybe with mixed case?
19 replies
-
You can by putting the if statements in the variables instead of at the top.
Something like:
let t := this; if Status = 1 then s1 code else let reply := if Status = 2 then 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"]) else 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"]) end; if reply = "Confirmed" then let today := if Status = 2 then Today + 7 else Today + 14; let newRec := duplicate(this); openRecord(newRec); newRec.('Audit Code' := null); newRec.(Status := null); newRec.(From := null); newRec.(Appointment := null); newRec.('Plan within' := if t.Status = 2 then 7 else 14 end); newRec.('Re Schedule Date' := today); let me := this; newRec.('Audit Code' := me.'Audit Code' + "_" + 1) end end
-
said:
No works on MAJOR Non Conformities but yes for MINOR Non Conformities.I forgot an end. I also updated the code to use a switch since you have more than 3 Status choices. The else would run even if you selected anything else but 1. Now it will only run if you select 1, 2 or 3.
let t := this; switch true do case t.Status = 1: ( 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 ) case t.Status = 2 or t.Status = 3: ( let title := if t.Status = 2 then " M A J O R - Non Conformities" else " 🟠 M I N O R - Non Conformities" end; let message := if t.Status = 2 then "This Audit was not compliant. Therefore, major non-conformities will be reviewed within 14 days." else "This Audit was not compliant. Therefore, minor non-conformities will be reviewed within 7 days." end; let reply := dialog(title, message, ["Confirmed", "No Confirmed"]); if reply = "Confirmed" then let today := if t.Status = 2 then Today + 7 else Today + 14 end; let newRec := duplicate(this); newRec.('Audit Code' := null; Status := null; From := null; Appointment := null; 'Plan within' := if t.Status = 2 then 7 else 14 end; 'Re Schedule Date' := Today; 'Audit Code' := t.'Audit Code' + "_" + 1 ) openRecord(newRec); end; ) end
It is 6 lines shorter than your original code, but it will be easier to update.
-
I came up with this, which tests the dialog first before proceeding to the update
let t := this; let title := [" 🟢 Audit To History"," M A J O R - Non Conformities"," 🟠 M I N O R - Non Conformities"]; let message := [" This Audit was Completed and will be archived and removed from Events","This Audit was not compliant. Therefore, major non-conformities will be reviewed within 14 days.","This Audit was not compliant. Therefore, minor non-conformities will be reviewed within 7 days."]; let days := [7,14]; if dialog(item(title,t.status-1),item(message,t.status-1),["Confirmed", "No Confirmed"]) = "Confirmed" then if t.Status = 1: (create 'History Completed').( 'Events Audited' := t; 'Audit No' := t.'Audit Code'; 'Project Audited' := t.'Projects_>'.'Project Name' Appointment := t.Appointment; text(Status := t.text(Status); Auditor := t.'Auditor_>'.('First Name' + " " + 'Last Name'); Audited := t.'To Audit_>'.('First Name' + " " + 'Last Name') ); alert(" Record Archived") else let newRec := duplicate(this); newRec.( 'Audit Code' := null; Status := null; From := null; Appointment := null; 'Plan within' := item(days,t,Status-2); 'Re Schedule Date' := today()+item(days,t.Status-2); 'Audit Code' := t.'Audit Code' + "_" + 1 ); openRecord(newRec); end end
Regards John
Content aside
- Status Answered
- 9 mths agoLast active
- 19Replies
- 72Views
-
3
Following