Cannot convert undefined or null to object - DynamoDB - json

Been testing some Lambda functions and finally managed to get the data to push to DyanmoDB, or at least in the logs it shows the billed duration and this only occurs after I've pushed data to the table, doesn't happen before I test the function.
Basically, I'm just testing a small function to push a UserID and Name to a DynamoDB table. I populate the params as seen below.
var UserID = toAdd['UserID']; var Name = toAdd['Name'];
var params = { Item: { 'UserID':UserID, 'Name':Name }, TableName: 'bookings2D' };
When I console log my params I'm seeing this:
dynamo.putItem(params, dynamoResultCallback);
And as you can see below, the request is at the very least being triggered.
However, when I navigate to my DB Table, and perform a table scan I receive this error:
This only occurs AFTER I run the Lambda function, if I delete and recreate the table this no longer appears. Seems like it's just something small format wise I may not be grasping.
Any help is much appreciated, any questions feel free to ask :)
Thanks

Hard refresh your browser page using CTRL + F5 or CTRL + Shift + R.

I had the same issue while creating table for phone (table name).
As a solution, I recreated the table with a different name (phone_detail).
AND IT WORKED!
You can also try to create table after a while.

Related

How do i get the User Image from a lookup list on Sharepoint 2013?

I'm really stuck with getting the User image from a lookup list using AJAX with SharePoint 2013.
Ok so im getting my data from a Sp list called 'Comments', and im selecting a SP generated field called 'Created By' however on my SP its actually called 'Author'. This field only shows an ID so ive expanded it with OData to get the 'Author' details.
So what im trying to do is set up a custom comment section. So im taking data from the 'Author / Created By' column and outputting that on top of the persons comment. This all works fine!
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/DigiBlog/_api/web/lists/getbyTitle('Comments')/items?$select=Comment,Likes,BlogId,Created,Author/ID,Author/FirstName,Author/LastName,Author/Title&$expand=Author/Id",
type: "GET",
headers: {
'accept': 'application/json;odata=verbose'
},
success: function (data) {
for (var i = 0; i < data.d.results.length; i++) {
var item = data.d.results[i];
self.blogComments.push(item);
//item.FirstName = item.FirstName.toLowerCase();
//console.log(item);
}
console.log("Comment User Info Called");
},
error: function () {
console.log("Comment User Info Error");
}
});
What i want is the picture Url from that user, so i can output an image of that person next to each comment. My Sharepoint is part of big organisation so theres a tonne of restrictions in place, one of which means i can't view the list of users so i can't see what fields i can actually use. Ive seen people use 'Picture' value in the select field, however when i try that the Ajax fails.
url: _spPageContextInfo.webAbsoluteUrl + "/DigiBlog/_api/web/lists/getbyTitle('Comments')/items?$select=Comment,Likes,BlogId,Created,Author/ID,Author/FirstName,Author/LastName,Author/Title&$expand=Author/Id",
All im looking for is the Author Img URl, ive tried Author/[Picture, PictureUrl, PictureUri, Image, ImageUri... and so on]. Ive spent 2 days on this and im not getting anywhere fast!
I either want a way to get the Picture Url or a way to show all the avaiable fields of 'Author' using console so i can find the relevant field i need to select.
Can anyone help? Thanks in advance!
It seems that we could not get picture url directly.
Firstly,you could get user name.
/_api/web/lists/getbytitle('Comments')/items(1)?$select=Owner/Name&$expand=Owner
Secondly,you could use this rest api to get picture url.
/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=#v)?#v='domain\username'&$select=PictureUrl
The different versions of rest api versions are introduced here.
Tip:The username obtained in the first step may need to be processed as in the example.

Strange results returning from Response.getId() in GAS

I am working with a script to pull the response ID from a form submission so that when users edit their response, I can match the edit to the initial response. My script creates a .pdf of the contents of each form submitted, but when users edit responses, it creates a new form containing only the edited data, without linking it to the initial response.
The edit response contains a timestamp and the edited information, and the timestamp is used with Response.getId(timestamp), iirc, and returns the ID of the form submission. However, I am sometimes getting a very strange return, and I don't know where it comes from. The response is much shorter than a typical response ID (10-12 alphanumeric instead of 30+). I will try to comeback and edit this question with the code, but I'm on a different log in at the moment, so I'll have to swap over and copy code and come back. Running unit tests hasn't really helped, as I get the expected result most of the time. It's just an occasional hiccup, but I have to find where the incorrect information is coming from.
function getResponseId(timestamp){
var form = FormApp.openById('<formID>');
if(typeof(timestamp) != 'number'){
timestamp = new Date(timestamp);
}
var responses = form.getResponses(timestamp);
var entryId = responses[0].getId();
return entryId;
}
That's is. I suppose the if(typeof... may be throwing things off if it's passing in a Date string instead of the actual timestamp of entry, but I don't think so. I'll double check it and debug it in the meantime, and if I answer my own question, I'll come back and fix it.
Hmm. Sounds like the same behavior. What I decided to do instead was to match the timestamps that are recorded, but you have to grab the stamps in the 3rd line of code, as the old stamp is overwritten quickly. I just subtracted oldTime from newTime, left a 5 sec window to match them, and that worked. I just haven't had a chance to post it yet, as I just got it working for new submissions, edits, and failed writes about an hour ago.

Updating a single row in TaffyDB

I currently have a database setup within an html page and my requirement is to update a single row within the application.
I could refresh the database with "fresh" data, but that would require too much time.
I had a look at
dbSports().update("aName", object.aname);
However it seems to update all the records in my database instead of just one. Are there any answers to this particular issue?
The Documentation on the matter is missing a major chunk of information, but is covered in a presentation done by the author of the library (http://www.slideshare.net/typicaljoe/better-data-management-using-taffydb-1357773) [Slide 30]
The querying object needs to be pointing to the object you want to update and editing happening from there. i.e.
var obj = dbObject({
Id : value.id
}).update(function() {
this.aName = object.aname;
return this;
});
Where the object in the query points to the ID of the row and the update function then points to it aswell and the callback updates the value that the application needs to update
you first have to find the matching record, then update it
yourDB({"ID":recordID}).update({
"col1":val1,
"col2":val2,
"col3":val3
});

Do views immediately reflect data changes in their underlying tables?

I have a view ObjectDisplay that is composed of two relevant tables: Object and State. State represents the state of an Object, and the view pulls some of the details from the most recent State for each Object.
On the page that is displaying this information, a user can enter some comments, which creates a new State. After creating the new State, I immediately pull the Object from ObjectDisplay and send it back to be dropped into a partial view and replace the Object in the grid on the page.
// Add new State.
db.States.Add(new State()
{
ObjectId = objectId,
Comments = comments,
UserName = username
});
// Save the changes (executes all of the above).
db.SaveChanges();
// Return the new Object information.
return db.Objects.Single(c => c.ObjectId == objectId);
According to my db trace, the Single call occurs about 70 ms after the SaveChanges call, and it occurs on the same SPID.
Now for the issue: The database defaults the value of RecordDate in State to GETUTCDATE() - I don't provide the date myself. What I'm seeing is that the Object returned has the State's RecordDate of the old State and the Comments of the new State information of the old State. I am seeing that the Object returned has the old State's information. When I refresh the page, all the correct information is there, but the wrong information is returned in the initial call from the database/EF.
So.. what could be wrong? Could the view not be updating quickly enough? Could something be going on with EF? I don't really know where to start looking.
If you've previously loaded the same Object entity in the same DbContext, EF will return the cached instance with the stale values, and ignore the values returned from SQL.
The simplest solution is to reload the entity before returning it:
var result = db.Objects.Single(c => c.ObjectId == objectId);
db.Entry(result).Reload();
return result;
This is indeed odd. In SQL Server views are not persisted by default and therefore show changes in the underlying data right away. You can create a clustered index on a view with effectively persists the query, but in that case the data is updated synchronously, so you should see the change right away.
If you are working with snapshot isolation level your changes might not be visible to other SPIDs right away, but as you are on the same SPID and do not use snapshot isolation, this cant be the culprit either.
The only thing left at this point is the application layer. Are you actually using the result of the Single call higher up in the call stack or does that get lost somewhere. I assume that a refresh of the page uses a different code path, which would explain why it is working there.

Titanium: How to reload a tab upon focus?

I have built a favorite-tab in my application that displays entries in a database that are flagged as such. On the backside this works as it should, but I can't figure out how to reload the favorites tab after changes have been made. When I quit and relaunch the app though, the updates appear as they should.
In essence I have the same problem as is presented here: http://developer.appcelerator.com/question/31211/tab---tableview--database-reload
"I have a 'search' and 'search history' tab in my application. Every search executed under this tab gets inserted into my local db.
However the new search is not reflected in the tableview retrieving data from the DB in the 'search history' tab when i browse to it, after searching.
The latest search, however, gets loaded when I exit the app and relaunch it.
I need some help in figuring out how to trigger the tableview reload without exiting the app.
SOLUTION UPDATE:
I feel 'noobish' for asking this question but it was really so simple
I added a 'focus' eventlistener for the window housing the tab to load the data.
win.addEventListener('focus', function() { loadDBdata(); });
This seems reasonable, but what should the loadDBdata function should contain?
I would greatly appreciate any pointers to this.
i would suggest firing an event when the favorites are updated and having an event listenter on the table that holds the favorites list. When it receives the event, it should update the tables contents.
see this question I just answered it should provide a guide for solving your problem also
Problems with refresh function for page, in Appcelerator
the loaddb function should contain something like:
// init database
var db = Ti.Database.install('path/to/database.db','myDB');
// your request
var sql = 'SELECT * FROM myDatabaseTable';
// the result from that request
var myContent = db.execute(sql);
// need to put the result in a valid structure before inserting into your tableview
var data = [];
while (myContent.isValidRow()){
// your tableviewrow
var row = {
title = myContent.field(0);
};
data.push(row);
myContent.next();
};
// need to close stuff (!)
myContent.close();
db.close();
// finally return data
return data;