Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var computeNormalizedValue = {
- name: "computeNormalizedValue",
- body: function compute() {
- var context = getContext();
- var collection = context.getCollection();
- var currentDocument = context.getRequest().getBody();
- var findPreviousDocumentQuery = {
- “query”: “SELECT * FROM ROOT WHERE ROOT.EventId2 = @eventId”,
- “parameters”: [
- {“name” : “@eventId”, “value” : currentDocument[‘eventId]}
- ]
- }
- var queryResult = collection.queryDocuments(
- collection.getSelfLink(),
- findPreviousDocumentQuery,
- setNormalizedValue);
- function setNormalizedValue(err, documents) {
- if(err) thow new Error(“Error: “ + err.message);
- if(documents.length < 1) {
- //handle no previous document
- }
- else {
- var previousDocument = documents[0];
- for(i = 0; i < documents.lenght; i++) {
- if(documents[i][‘Date’].getTime() > previousDocument[‘Date’].getTime()) {
- previousDocument = documents[i];
- }
- }
- var normalizedValue = currentDocument[‘ClusterizeAttendees’] - previousDocument[‘ClusterizeAttendees’]...
- currentDocument[‘NormalizedValue’] = normalizedValue;
- }
- }
- },
- triggerType: TriggerType.Pre,
- triggerOperation: TriggerOperation.Create
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement