Page 1 of 2

Update service using 'whereobject'?

Posted: Fri Nov 14, 2014 3:13 am
by Peter Viglietta

Please see the screenshot below. If someone could help me out with the code I would appreciate it
Image


Update service using 'whereobject'?

Posted: Fri Nov 14, 2014 5:33 am
by Yurii Orishchuk

Hi Peter,

Here is code for you:

pre

var messageThreadId = localStorage.getItem("MessageThreadId");
var sentToId = localStorage.getItem("CurrentUserId");

var whereObject = {
$and: [
MessageThreadId: messageThreadId,
SentToId: sentToId
]
};

//Where:
//updateMessagesService - service datasource name.
updateMessagesService.execute({body: {where: JSON.stringify(whereObject), operations: {$set: {IsRead: true} } } });

/pre

Please check LSV and parameter names.

Regards.


Update service using 'whereobject'?

Posted: Fri Nov 14, 2014 1:29 pm
by Peter Viglietta

Thanks Yurii. Where do I put this code? Is this for Events page load run JS?


Update service using 'whereobject'?

Posted: Mon Nov 17, 2014 12:18 am
by Yurii Orishchuk

Hi Peter,

You should put this code on action you need.

This code will invoke update service that's mark all self messages in given thread ad read.

So i guess you can place this code on message list service "success" event.

Also don't forget to check LSV and parameter names as well as update service datasource name.

Regards.


Update service using 'whereobject'?

Posted: Tue Nov 18, 2014 2:40 am
by Peter Viglietta

Yurii,

I tried this code and it didn't work. I'm trying to update the Messages collection so that the IsRead boolean column gets updated to true for every row where the SentToId is equal to LSV 'CurrentUserId' and MessageThreadId is equal to the LSV MessageThreadId. I verified the correct name of the service and LSVs. Any idea?

var messageThreadId = localStorage.getItem("MessageThreadId");
var sentToId = localStorage.getItem("CurrentUserId");
var whereObject = {
$and: [
{MessageThreadId: messageThreadId},
{SentToId: sentToId}
]
};

//Where:

//updateMessagesService - service datasource name.
MessagingUpdate.execute({body: {where: JSON.stringify(whereObject), operations: {$set: {IsRead: true} } } });


Update service using 'whereobject'?

Posted: Tue Nov 18, 2014 11:27 pm
by Yurii Orishchuk

Hi Peter,

please debug this request with browser debug tool.

You need to open "net" tab and find request on this update. Make sure there is correct data in this request.

And if you can not understand a problem show us the screen shot where we can found all request parameters and headers. Also please show us response of this request.

Regards.


Update service using 'whereobject'?

Posted: Sat Nov 22, 2014 9:52 pm
by Peter Viglietta

Yurii,

To review.. what I'm trying to do here is make it so that when the user opens the messages page and views new messages, it sets "IsRead" to 'true' on the row in the Messages table. I currently have it set so that you open the messages page, it runs the Messages Query service, and at success of the Messages Query service, it runs this Javascript, to invoke MessagingUpdate service, which will update the property IsRead on the messages table to 'true'. I used the debugger and it looks like there's an error.. Name 'api.appery.io', status 400 Bad Request

Headers:

Request URL:https://api.appery.io/rest/1/db/colle...
Request Method:PUT
Status Code:400 Bad Request400 Bad Request
Request Payload
{"acl":{"*":{"write":true,"read":true}}}
Response Headers
Content-Type:application/json

Content:

{"code":"DBSP260","description":"Object must be present in the request body"}

And here's a screenshot of request and response parameters/headers:

Image


Update service using 'whereobject'?

Posted: Sun Nov 23, 2014 11:50 pm
by Yurii Orishchuk

Hi Peter,

pre

{"code":"DBSP260","description":"Object must be present in the request body"}

/pre

This response means - you did not pass value to "_id" parameter. Or this value is empty. Also you can use "where" and "$set" parameters to do it.

But in you screen shot i can not see these parameters.

http://prntscr.com/59hl1x/direct

Regards.


Update service using 'whereobject'?

Posted: Mon Nov 24, 2014 2:06 am
by Peter Viglietta

I didn't pass anything to the _id parameter because I want to do a 'where' statement.

There is no where parameter becuase it's an update service.

Can someone please review this.


Update service using 'whereobject'?

Posted: Mon Nov 24, 2014 5:14 am
by Yurii Orishchuk

Hi Peter,

Please read following documentation to understand how to update several items per single request using "where" and "$set" parameters.

http://devcenter.appery.io/documentat...

Then please review my first question in this topic to understand how to invoke the service with these parameters.

Regards.