Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

Update service using 'whereobject'?

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Update service using 'whereobject'?

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.

Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

Update service using 'whereobject'?

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Update service using 'whereobject'?

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.

Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

Update service using 'whereobject'?

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} } } });

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Update service using 'whereobject'?

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.

Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

Update service using 'whereobject'?

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

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Update service using 'whereobject'?

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.

Peter Viglietta
Posts: 0
Joined: Sat Jul 05, 2014 6:22 pm

Update service using 'whereobject'?

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.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Update service using 'whereobject'?

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.

Return to “Issues”