How prevent duplicate records in appmaker? - google-app-maker

I have tried the code below but encountered some errors:
var query = app.models.Hardware.newQuery();
query.filters.HardwareId._equals = record.HardwareId;
if (query.run().length) {
throw 'Hardware ID "' + record.HardwareId + '" is in use.';
}
Errors encountered below:
Saving records: (Error) : Cannot set property "_equals" of undefined to "undefined".
at models.CheckpointBooking.onAfterCreateEvent:2
at saveChanges (ChkPointEditPgAction:54:21)
at ChkPointPageFm.Form1.Form1Footer.Form1SubmitButton.onClick:1:1
What am I doing wrong?

Related

Suitescript 2.0 - log.debug repeating value lines

I'm working on a client script, but when I do a simple getValue() on the customer field and log.debug, I get repeating output lines and I'm not sure why. Is this normal?
Output
This my fieldChanged code:
function fieldChanged(context) {
var newRec = context.currentRecord;
if(newRec.fieldId = 'entity') {
var custId = newRec.getValue ({
fieldId: 'entity'
});
log.debug({
title: 'id: ' + custId
});
}
}
Change the line below:
if(newRec.fieldId = 'entity')
To something like
if(context.fieldId === 'entity')
You're getting repeating output lines because whenever a field is changed, you're not doing a check on the current fieldId in the context object instead checking the context.currentRecord.fieldId which I'm not sure what evaluates to.
Check this out for more info: fieldChanged(scriptContext)

Odd Behavior with MembershipCreateStatus.Success

I'm having some really odd behavior with some code that creates an ASP.Net user and then checks for success. The problem is, it seems to run code in BOTH branches of the if else:
if (result == MembershipCreateStatus.Success)
{
ErrorLog("MembershipCreateStatus.Success for user: " + Email.Text);
}
else
{
ErrorLog("But also got here for non-successful creation of new user??? new user: " + Email.Text);
// No Success
lblPanel4.Text = GetErrorMessage(result) + " #2";
}
When I look at my log files they show both error messages:
MembershipCreateStatus.Success for user: man57#t.com 1/4/2021 8:13:59 PM
But also got here for non-successful creation of new user??? new user: man57#t.com 1/4/2021 8:14:00 PM
I've looked through the code and this method is getting called twice, wrapped into to different event handlers for two separate buttons. Only one of them is being clicked on my page, so I can't see this as somehow running twice accidentally.

Meteor getting caught in infinite loop in Tracker

This is further information from a previous submission but I thought it would be clearer if I posted this separately.
A helper is returning a collection query:
Template.clientGrid.helpers({
'programs': function () {
var fullNameP = Session.get('clientName');
return Programs.find({FullName: fullNameP});
}
});
In the template it's printing out properties from 'programs'. For example:
...
{{#each programs}}
<p>{{formatCampYear CampYear}}: {{formatNotes Notes}}</p>
{{/each}}
....
Nothing special going on. So, if the FullName is Jane Doe, and she's got 6 documents in the programs collection, it will print the six properties in the template. But the page is getting caught in a while-loop inside Tracker (see line 449 the while-loop 'recompute all pending computations') after the properties finish printing. The CPU is tied up and prevents certain page operations. If any of you harder-core guys and gals have any clue as to what this means, perhaps I can sleuth out the problem. Here's a copy of the while loop itself (just in isolation):
// recompute all pending computations
while (pendingComputations.length) {
var comp = pendingComputations.shift();
comp._recompute();
if (comp._needsRecompute()) {
pendingComputations.unshift(comp);
}
if (! options.finishSynchronously && ++recomputedCount > 1000) {
finishedTry = true;
return;
}
}
EDIT: Here's the event map that setting the session. There doesn't seem to be anything suspicious. Since I'm pre-production, I'm not doing any updates to the collection. It's pretty much just static at this point.
Template.clientSearchButton.events({
'click #client-search-button': function(event) {
event.preventDefault();
var clientFullName = document.getElementById('full-name').value.toUpperCase();
Session.set('clientName', clientFullName);
mapAddress = Demographic.find({ "FullName": clientFullName }).map(function (a) { return (a.Address + " " + a.City + " " + a.State + " " + a.Country); });
Meteor.myFunctions.initialize();
}
});

SQLite update query is not updating table data with phonegap3.1

I am new user for SQLite. I am using phonegap3.1 foe android. I have an issue while updating user table. Below is the code that I am using:
var db = window.openDatabase("riazdb", "1.0", "Demo", 200000);
var userName = "user1";
db.transaction(function(tx) {
tx.executeSql('UPDATE user SET auto_login = "true" WHERE name = ?', [userName], userUpdateSuccess, userUpdateError);
}, userUpdateError);
function userUpdateSuccess(tx, results) {
console.log("affected rows : "+results.rowsAffected);
}
function userUpdateError(err) {
console.log("userUpdateError");
}
I am getting response as a success with results.rowsAffected = 1.
Can somebody tell me that what am I doing wrong.
Thanks
I had the exact same scenario.
Take a look in your onSuccess callback. If there is an unhanded exception thrown from your onSuccess handler, you will see the success happen, you will see rowsAffected == 1. However I suspect that the exception in the success handler causes phonegap to never WRITE the results to the table.
HTH

Firebase child_added creates duplicates

I am using Firebase to develop an HTML5 mobile messaging app. I encountered an issue that I am unable to resolve. The app has multiple channels (chat rooms). When a message is added for the first time to a channel it works as expected but when I go to a different channel and post an new message to that channel then I return to the previous channel and post another message I get duplicates of the last posted message. When I reload the page the duplicates are gone but I'd prefer not to have duplicates showing at all. Below is my code:
function loadChatMessages(channelID) {
$('#chatMessages').html('');
var msgObj = {};
var channelRef = globals.channelsBase + '/' + channelID + '/messages';
var channelMessages = new Firebase(channelRef);
channelMessages.on('child_added', function (snapshot) {
msgObj = snapshot.val();
var id = snapshot.name().toString();
var messageTime = application.Functions.renderTime(msgObj.messageTime);
var tails = '<div class="message-tails-wrap"><div class="message-tails"></div></div>';
var html = '<li class="chatEl ' + sentByClass + '" id="'+id+'">';
html += tails;
html += msgObj.message;
html += '<span class="sender"> ' + by + ' </span> <span class="tmp-recipient"> ' + msgObj.recipient + ' </span>';
html += '<span class="time-stamp msg-time" >';
html += messageTime;
html += '</span></li>';
$(html).appendTo('#chatMessages');
/// TODO: TEMP solution!
var prevID = 0;
$('#chatMessages li').each(function(n) {
var id = $(this).attr('id');
if(id == prevID){
// console.log(id + ' is a duplicate. Remove it');
this.remove(); // the necessary evil....
}
prevID = id;
});
});
}
It sounds like you run loadChatMessages() every time you enter a room, and as your users move around rooms, you're seeing duplicate calls to your on('child_added' callback.
This is because you're adding a new callback every time you re-enter a room. To resolve this, do some clean up when your users leave a room. In that clean up function, make sure you remove the old listener using .off("child_added").
The event :
YOURREF.limitToLast(1).on('child_added', function (OBJECTADDED){
console.log(OBJECTADDED.key(), OBJECTADDED.val());
});
You may think the above code will e fired one time, this is not true. The above console.log will be fired twice, once with OBJECTADDED as the last object in the reference YOURREF before adding the new one, and another with the new one.

Resources