0

I'm following this example. https://learn.microsoft.com/en-us/azure/azure-functions/functions-integrate-store-unstructured-data-cosmosdb

Instead of using C# as in the example, I want to use JavaScript. But I'm trying to figure out how this part is written in JS.

taskDocument = new {
    name = name,
    duedate = duedate.ToString(),
    task = task
};

I tried the above, and below, but both threw an exception.

taskDocument = new {
    name: name,
    duedate: duedate,
    task: task
};

Guess it is a simple task for those who know how it works.

2 Answers 2

2

The proper syntax for object initialization is

let taskDocument = {
    name: name,
    duedate: duedate,
    task: task
};

You then need to assign this value to the output binding, i.e. to context.bindings.taskDocument.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, yes I updated my answer with my final code. It is basically the same as the code you posted. I will award you with the correct answer :)
0

Okay, it was just me being stupid. It should have been like this.

taskDocument = {
    name: name,
    duedate: duedate,
    task: task
};

No new in JS :P

Update

Complete example.

context.bindings.taskDocument = JSON.stringify({ 
   name: name,
   duedate: duedate,
   task: task
});

1 Comment

Would you mind sharing the rest of your function code? I'm very new to how Azure works and am trying to set it up using Javascript as well, however, there are not many examples out there on how to accomplish it in JS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.