Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I avoid duplicates in ScriptDb?
    primarykey
    data
    text
    <p>I have some objects to save in the database, but they must be unique every time the script is executed. These objects are just going to change values every instance of the application. The problem is that when I create the first object, more copies are also created every time the script is executed after that. I try to use the same object again, but when I do the query, I get objects from previous executions giving me the wrong values. I just want to be able to reset the same objects to their default values and not have many unnecessary copies in the ScriptDb. </p> <p>Here is some code:</p> <pre><code>// Get a database instance var database = getDb(); // Create a new employee instance var myEmployee = { element: "currentEmployee", firstName: "", lastName: "", ID: 0, manager: "", managerEmail: "", department: "1 - University Store", startDate: "", endDate: "", regularHours: 0, vacationHours: 0, sickHours: 0, personalHours: 0, H2Hours: 0, overtimeHours: 0, totalHours: 0, rowLocation: 0, salaryType: "H", }; var week1 = { // Identify the week and for query purposes element: "Week1", // User entries HW: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, VH: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, SH: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, PH: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, TH: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, // Calculated totals TotalHW:0, TotalVH: 0, TotalSH: 0, TotalPH: 0, TotalHours: 0, // Week totals Vacation: 0, Sick: 0, Personal: 0, H2: 0, OT: 0, Regular: 0, } var week2 = { // Identify the week and for query purposes element: "Week2", // User entries HW: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, VH: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, SH: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, PH: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, TH: {THUR: 0, FRI: 0, SAT: 0, SUN: 0, MON: 0, TUES: 0, WED: 0}, // Calculated totals TotalHW:0, TotalVH: 0, TotalSH: 0, TotalPH: 0, TotalHours: 0, // Week totals Vacation: 0, Sick: 0, Personal: 0, H2: 0, OT: 0, Regular: 0, } // Save these to the database database.save(myEmployee); database.save(week1); database.save(week2); </code></pre> <p>Then, I would use the statement <code>ScriptDb.getMyDb.query({element: element}).next()</code> to retrieve the object. The string element containing "currentEmployee", "Week1", or "Week2".</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload