Custom scripts understanding


#1

I don’t quite understand server side scripting,
I know theres documentation for this, but got problems getting through.

Just want very simple script. :frowning:
When user add data to table A (through restAPI),
then get part data of that call and put it into another. (Notifications)

So I thought it’ll be simple as that:
if (event.response.record.lenght) {
_.each(event.response.record, function(record, index, list) {
var data = {“to”: record.to, “type”: 1, “set”: record.plan_id, “who”: record.user_id};
platform.api.post(“plansth.notifies”, data);
});
}
plansth is app and service name, the rest lok quite obvious.
Where did I go wrong?


#2

You have a typo in event.response.record.lenght

In platform.api.post(“plansth.notifies”, data) is your service API name “plansth.notifies”?

To help with debugging you can use print and var_dump to write to the log file in the /log directory of your DSP.


#4

.Och, right, I often make this typo (don’t know why only with lenght).
my API name is plansth tablename is notifies

I’ll try this logging, thanks.


#5

No worries I’ve made the same typo before :smile:

In platform.api.post() you want to use service/resource which in your case would be plansth/notifies.

/ not .