Android QuickBlox - CustomObject Push to Array Field - quickblox

Hi I'm using CustomObject to bulid friends list but I'm facing below problem.
When I try to push a number to an array field it returns null value and the field is not updated but if I add it as a normal field (not pushing to array) it works fine.
Below is my code:
QBCustomObject friendsList = new QBCustomObject();
friendsList.setClassName("Friends");
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("push[friendsId][]", "00001111");
friendsList.setFields(fields);
and logcat shows below api request:
https://api.quickblox.com/data/Friends.json?push[friendsId][]=00001111
but if I use below code it works but not append to array. It adds new record:
fields.put("friendsId", "00001111");
friendsList.setFields(fields);
Is there anything wrong with my way?

To update your record, your URL should look like
https://api.quickblox.com/data/Friends/id.json?push[friendsId][]= 00001111,
where id is a record id.
For example,
https://api.quickblox.com/data/Friends/111c0ec5535c12669c000721.json?push[friendsId][]= 00001111
Did my answer helped you ?

You can rewrite the whole record. Don't try to add an object separately into an array, update the whole record.

Related

Microsoft Graph API not returning custom column from list

Working in VB.Net, using the Microsoft.Graph api communicate with sharepoint.
I have a list on a sharepoint site.
Lets say:
List name : ListTestName
Columns: ListColumnTest1, ListColumnTest2, ListColumnTest3
Dim queryFields As List(Of QueryOption) = New List(Of QueryOption) From {New QueryOption("$expand", "fields")}
Dim items As IListItemsCollectionPage = Await GraphClient.Sites(sharepointSessionId).Lists("ListTestName").Items.Request(queryFields).GetAsync()
This is the code I have to grab the list and trying to get all of the fields (columns) but when I look into the Fields in the "Items" variable I do not see any of the fields that I have added to the list. I only see the sharepoint fields such as "title" or "Id"
I really dont understand why this is not working.
Even when I look via the the graph-explorer site (https://developer.microsoft.com/en-us/graph/graph-explorer) using:
GET https://graph.microsoft.com/v1.0/sites/<SiteId's>/lists/ListTestName/items?expand=fields
I do not see my custom columns However if I try and filter directly to one of the columns like this :
GET https://graph.microsoft.com/v1.0/sites/<SiteId's>/lists/ListTestName/items?expand=fields(select=ListColumnTest1)
This does seem to have returned back my custom field.
Thus I tried adding to the query field {New QueryOption("$expand", "fields(select=ListColumnTest1")} this just crashed when I called the request.
Edit: I asked this question slightly wrong and will be posting a second question that is more to what I need. However, below the question is marked correct because their solution is the correct solution for what I asked. :)
Have you try this endpoint?
GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}?expand=columns,items(expand=fields)
I could get the custom columns with this endpoint.
Updated:
IListColumnsCollectionPage columns = graphClient.Sites["b57886ef-vvvv-4d56-ad29-27266638ac3b,b62d1450-vvvv-vvvv-84a3-f6600fd6cc14"].Lists["538191ae-7802-43b5-90ec-c566b4c954b3"].Columns.Request().GetAsync().Result;
I would avoid to create QueryOption. Try to use Expand and Select method.
Example (C#...apologise I'm not familiar with VB but I hope it will easy for you to rewrite it):
await GraphClient.client.Sites[sharepointSessionId].Lists["ListTestName"].Items.Request()
.Expand(x => new
{
ListColumnTest1 = x.Fields.AdditionalData["ListColumnTest1"],
ListColumnTest2 = x.Fields.AdditionalData["ListColumnTest2"]
})
.Select(x => new
{
ListColumnTest1 = x.Fields.AdditionalData["ListColumnTest1"],
ListColumnTest2 = x.Fields.AdditionalData["ListColumnTest2"]
})
.GetAsync();

How to create hashMap that has a list of hashmap in kotlin?

What I am trying to achieve is is a map that has a list of maps in which the first key is ID and value obviously is a map of which the key is Session and the value is an OBJECT.
var newSession = ConcurrentHashMap<String, ConcurrentHashMap<WebSocketSession, String>>()
What if I want to save multiple session maps with the same ID? Whenever I pass an ID I want to get a map from which I should be able to search a particular session?
Sorry for not being so clear, but I am stuck here for a while and am kinda newbie in Kotlin!
Thanks in advance!

How to create several new records in another SQL table from one button-click

I'm new here. Thanks in advance for your advice.
I’m working on an app which will ask the user how many items they made.
The user will enter a number. My app should then create that many new records in a table called 'Items_Made'.
E.g. The app asks “How many items did you make?”, the user enters “19”, the app then creates 19 new records in the 'Items_Made' table.
I've managed to pull together some code (shown below) that creates ONE new record, but I would like it to create several. I probably need some kind of loop or 'while' function but am unsure how to do so.
var ceateDatasource = app.datasources.Items_Made.modes.create;
var newItem = ceateDatasource.item;
ceateDatasource.createItem();
This code successfully creates 1 record. I would like it to be able to create several.
Creating a lot of records via client script is not recommended, especially if you loose connection or the app gets closed by mistake. In my opinion, the best way to handle this would be via server script for two things: First, It's more reliable and second, it's faster. As in the example from the official documentation, to create a record you need to do something like this:
// Assume a model called "Fruits" with a string field called "Name".
var newRecord = app.models.Fruits.newRecord();
newRecord.Name = "Kiwi"; // properties/fields can be read and written.
app.saveRecords([newRecord]); // save changes to database.
The example above is a clear example on how to create only one record. To create several records at once, you can use a for statement like this:
function createRecordsInBulk(){
var newRecords = [];
for(var i=0; i<19; i++){
var newRecord = app.models.Fruits.newRecord();
newRecord.Name = "Kiwi " + i;
newRecords.push(newRecord);
}
app.saveRecords(newRecords);
}
In the example above, you initiate newRecords, an empty array that will be responsible for holding all the new records to create at once. Then using a for statement, you generate 19 new records and push them into the newRecords. Finally, once the loop is finished, you save all the records at once by using app.saveRecords and passing the newRecords array as an argument.
Now, all this is happening on the server side. Obviously you need a way to call this from the client side. For that, you need to use the google.script.run method. So from the client side you need to do the following:
google.script.run.withSuccessHandler(function(result) {
app.datasources.Fruits.load();
}).createRecordsInBulk();
All this information is clearly documented on the app maker official documentation site. I strongly suggest you to always check there first as I believe you can get a faster resolution by reading the documentation.
I'd suggest making a dropdown or textbox where the user can select/enter the number of items they want to create and then attach the following code to your 'Create' button:
var createDatasource = app.datasources.Items_Made.modes.create;
var userinput = Number(widget.root.descendants.YourTextboxOrDropdown.value);
for (var i = 0; i <= userinput; i++) {
var newItem = createDatasource.item;
createDatasource.createItem();
}
Simple loop with your user input should get this accomplished.

dojo 1.10 JsonRest idAttribute - server passed a float in PUT

Just getting started with dojo/JsonRest, but having some problems with sending updates back to my server. I've got 2 questions that I'm stuck with;
The code below produces a grid with one of the columns set to editable.
The primary key in my json data is the "jobName" attribute (hence idAttribute in the JsonRest store).
First question is about the URI in the PUT;
- When I call dataStore.save() the server get's a PUT, but the URI is /myrestservice/Jobs/0.9877865987 (it changes each time, but is always a float)
- I don't see where dojo is getting the float number from? It's not my idAttribute value from that row. How can I get the PUT to respect the idAttribute in the JsonRest store?
- I did try setting idProperty in the MemoryStore to "jobName", but that changed the PUT in to a POST and removed the float, but I still don't get a jobName in the URI which is what my REST server needs.
Second question about the content of the PUT;
- The PUT contains the whole row. I'd really just like the idAttribute and the data that changed - is that possible?
I've been through the examples and docs, but there aren't many examples of handling the PUT/POST part of JsonRest.
Thanks
var userMemoryStore = new dojo.store.Memory( );
var userJsonRestStore = new dojo.store.JsonRest({target:"/myrestservice/Jobs/", idAttribute:"jobName"});
var jsonStore = new dojo.store.Cache(userJsonRestStore, userMemoryStore);
var dataStore = new dojo.data.ObjectStore( {objectStore: jsonStore } );
/*create a new grid*/
var grid = new dojox.grid.DataGrid({
id: 'grid'
,store: dataStore
,structure: layout
,rowSelector: '20px'}
,"gridDiv");
grid.startup();
dojo.query("#save").onclick(function() {
dataStore.save();
});
I think you want idProperty, not idAttribute. It also might help to set idProperty in the Memory store being used to cache as well; that may be what's generating the random float.
As for the second question, that'd probably require customization; I don't believe OOTB stores (or grids) generally expect to send partial items.

Add users to UserMulti field type using Client Object Model

I'm bit of a SharePoint noobie so please bear with me.
I need to be able to create a new list item in one our custom list using the client object model. I have been following the example described on the MSDN site and for the most part this has worked.
We have a list that contains several fields including a UserMulti field type. I am having problems adding users to this field. So far I have tried the following but this somehow always seems to default to the system account rather than the user specified in the field.
...
listItem["ProjectMembers"] = "1;#domain\\johndoe";
listItem.Update();
_clientContext.ExecuteQuery();
Do I need to do some type of lookup first? Any help is appreciated. Thanks.
It took a little while but I figured it out in the end. Below are two approaches you can take
Assign a Principal to the list item
var principal = _rootWeb.EnsureUser("domain\\johndoe") as Principal;
listItem["ProjectMembers"] = principal;
listItem.Update();
_clientContext.ExecuteQuery();
Assign an list of FieldUserValue if you need to assign more than one user to the field.
string[] users = { "domain\\johndoe", "domain\\peterpan" };
var projectMembers = users
.Select(loginName => FieldUserValue.FromUser(loginName))
.ToList();
listItem["ProjectMembers"] = projectMembers;
listItem.Update();
_clientContext.ExecuteQuery();
I'm sure there's better ways of doing things and you could combine the two to ensure that the users are valid before adding them to the list, but this is working so far. Hope this help someone else.
Microsoft has a wiki article, "SharePoint: A Complete Guide to Getting and Setting Fields using C#" that can help. http://social.technet.microsoft.com/wiki/contents/articles/21801.sharepoint-a-complete-guide-to-getting-and-setting-fields-using-c.aspx#Set_and_Get_a_Multi-Person_Field
It includes this sample code.
var lotsofpeople = new SPFieldUserValueCollection(web, item["lotsofpeoplefield"].ToString());
var personA = web.EnsureUser("contoso\\fred");
var personAValue = new SPFieldUserValue(web, personA.ID, personA.LoginName);
var personB = web.EnsureUser("contoso\\barnie");
var personBValue = new SPFieldUserValue(web, personB.ID, personB.LoginName);
lotsofpeople.Add(personAValue);
lotsofpeople.Add(personBValue);
item["lotsofpeoplefield"] = lotsofpeople;
item.Update();