I am getting an error when calling the grabBagAdd() method using the FatFractal JavaScript (HTML5) SDK. For this particular problem, my data model is simple, and only involves two object types: a custom Team object and the default FFUser object.
Relevant FFDL Declarations:
CREATE OBJECTTYPE FFUser (userName STRING, firstName STRING, lastName STRING, email STRING, active BOOLEAN, authDomain STRING, groups GRABBAG /FFUserGroup, notif_ids GRABBAG /FFNotificationID)
CREATE OBJECTTYPE Team (teamName STRING, members GRABBAG /FFUser)
CREATE COLLECTION /FFUser OBJECTTYPE FFUser
CREATE COLLECTION /Teams OBJECTTYPE Team
JS Object Declarations:
function Team(data){
if(data){
this.clazz = data.clazz;
this.guid = data.guid;
this.teamName = data.teamName;
}
else{
this.clazz = "Team";
this.guid = null;
this.teamName = null;
}
return this;
}
function FFUser(data){
if(data){
this.clazz = data.clazz;
this.userName = data.userName;
this.firstName = data.firstName;
this.lastName = data.lastName;
this.email = data.email;
this.active = data.active;
this.guid = data.guid;
}
else{
this.clazz = "FFUser";
this.userName = null;
this.firstName = null;
this.lastName = null;
this.email = null;
this.active = null;
this.guid = null;
}
return this;
}
I'm simply attempting to add an FFUser to a selected Team's members grab bag. I am using KnockoutJS bindings to display my web app's data and KnockoutJS observables to store the data locally. The pertinent steps in the use case generating the error are as follows:
Pull Teams from my app's back-end after user logs in. Below, self.teams
is an observable array which is bound to an HTML select menu.
function loadTeams() {
ff.getArrayFromUri("/ff/resources/Teams",function(loadedTeams) {
if(loadedTeams.length > 0) {
for(var i = 0; i < teams.length; i++) {
var team = new Team(loadedTeams[i]);
self.teams.push(team);
}
}
else console.log("No teams to load!");
},function(statusCode,responseText) {
alert(JSON.parse(responseText).statusMessage);
});
};
The user selects a team from the select menu and enters a username to add as a team member. Upon submission, the grabBagAdd() is executed. Below, self.selectedTeam
is an observable bound to the value of the select menu and contains one of the Team objects from self.teams
. Also, self.addMemberEmail
is an observable bound to the value of the username input box.
self.addMember = function() {
if(self.addMemberEmail()) {
ff.getObjFromUri("/ff/resources/FFUser/(userName eq '" + self.addMemberEmail() + "')",function(user) {
if(user){
var member = new FFUser(user);
ff.grabBagAdd(member,self.selectedTeam(),"members",function() {
console.log("Added member to grabbag!");
},function(statusCode,responseText) {
alert(JSON.parse(responseText).statusMessage);
});
}
else alert("No users found with the provided username.");
},function(statusCode,responseText) {
alert(JSON.parse(responseText).statusMessage);
});
}
else alert("Must provide member email.");
};
FatFractal returns a 400: Bad Request
error as follows:
FatFractal.handleGrabBagRequest 400, {"result":null,"statusMessage":"Cannot add NULL items to a object's grab bag"}
Not sure what to make of the error. Any help would be appreciated!