// Fetch the current record from the AMER form
previous_record = AMER[ID == input.ID];
info "Previous Record: " + previous_record;
// Fetch the record from the AMER form by its unique ID
previous_status = previous_record.Status; // Get the old status
info "Previous Status: " + previous_status;
// Get the updated device status
current_status = input.Status;
info "Current Status: " + current_status;
// Define the statuses that should trigger an entry in the IN/OUT_Test form
trigger_statuses_out = List();
trigger_statuses_out.add("Sold");
trigger_statuses_out.add("Discarded");
trigger_statuses_out.add("Missing");
trigger_statuses_out.add("Active");
trigger_statuses_in = List();
trigger_statuses_in.add("Deprovisioning");
trigger_statuses_in.add("Spare (Old)");
trigger_statuses_in.add("Spare (New)");
trigger_statuses_in.add("Damaged");
trigger_statuses_in.add("Legal Hold");
info "Trigger Statuses OUT: " + trigger_statuses_out;
info "Trigger Statuses IN: " + trigger_statuses_in;
// Check if the status has changed and if it is one of the trigger statuses
if (current_status != previous_status && (current_status in trigger_statuses_out || current_status in trigger_statuses_in)) {
// Determine IN or OUT based on the current status
in_out_status = "IN";
if (current_status in trigger_statuses_out) {
in_out_status = "OUT";
}
// Create a new record in the IN/OUT_Test form
new_record = insert into IN_OUT_Test
.set("IN_OUT", in_out_status)
.set("SERIAL_NUMBER", input.Serial_Number)
.set("Computer_Name1", input.Computer_Name)
.set("ASSIGN_UNASSIGN_DATE", zoho.currentdate)
.set("USER_LOCATION", input.Location)
.set("DEPARTMENT", input.Department)
.set("Model_Description", input.Model_Description)
.set("AU_Email", input.Assigned_User_Email)
.set("Last_User", input.Last_User)
.set("Added_User", zoho.loginuser);
info "New record created: " + new_record;
} else {
info "Condition not met for creating a new record.";
}