Skip to content

Commit 7bc1efd

Browse files
committed
Add JavaScript binding documentation
1 parent a836c79 commit 7bc1efd

File tree

1 file changed

+66
-10
lines changed

1 file changed

+66
-10
lines changed

articles/azure-functions/functions-bindings-event-grid.md

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ The Event Grid instance is available via the parameter configured in the *functi
383383

384384
# [Java](#tab/java)
385385

386-
The Event Grid event instance is available via the parameter associated to the `EventGridTrigger` attribute, typed as an `EventSchema`. See the [example](#trigger-example) for more detail.
386+
The Event Grid event instance is available via the parameter associated to the `EventGridTrigger` attribute, typed as an `EventSchema`. See the [example](#trigger---example) for more detail.
387387

388388
---
389389

@@ -686,15 +686,71 @@ public static void Run(TimerInfo myTimer, ICollector<EventGridEvent> outputEvent
686686

687687
# [JavaScript](#tab/javascript)
688688

689-
The Event Grid output binding is not available for JavaScript.
689+
The following example shows the Event Grid output binding data in the *function.json* file.
690+
691+
```json
692+
{
693+
"type": "eventGrid",
694+
"name": "outputEvent",
695+
"topicEndpointUri": "MyEventGridTopicUriSetting",
696+
"topicKeySetting": "MyEventGridTopicKeySetting",
697+
"direction": "out"
698+
}
699+
```
700+
701+
Here's JavaScript code that creates a single event:
702+
703+
```javascript
704+
module.exports = async function (context, myTimer) {
705+
var timeStamp = new Date().toISOString();
706+
707+
context.bindings.outputEvent = {
708+
id: 'message-id',
709+
subject: 'subject-name',
710+
dataVersion: '1.0',
711+
eventType: 'event-type',
712+
data: "event-data",
713+
eventTime: timeStamp
714+
};
715+
context.done();
716+
};
717+
```
718+
719+
Here's JavaScript code that creates multiple events:
720+
721+
```javascript
722+
module.exports = function(context) {
723+
var timeStamp = new Date().toISOString();
724+
725+
context.bindings.outputEvent = [];
726+
727+
context.bindings.outputEvent.push({
728+
id: 'message-id-1',
729+
subject: 'subject-name',
730+
dataVersion: '1.0',
731+
eventType: 'event-type',
732+
data: "event-data",
733+
eventTime: timeStamp
734+
});
735+
context.bindings.outputEvent.push({
736+
id: 'message-id-2',
737+
subject: 'subject-name',
738+
dataVersion: '1.0',
739+
eventType: 'event-type',
740+
data: "event-data",
741+
eventTime: timeStamp
742+
});
743+
context.done();
744+
};
745+
```
690746

691747
# [Python](#tab/python)
692748

693-
The Event Grid output binding is not available for JavaScript.
749+
The Event Grid output binding is not available for Python.
694750

695751
# [Java](#tab/java)
696752

697-
The Event Grid output binding is not available for JavaScript.
753+
The Event Grid output binding is not available for Java.
698754

699755
---
700756

@@ -723,15 +779,15 @@ Attributes are not supported by C# Script.
723779

724780
# [JavaScript](#tab/javascript)
725781

726-
The Event Grid output binding is not available for JavaScript.
782+
Attributes are not supported by JavaScript.
727783

728784
# [Python](#tab/python)
729785

730-
The Event Grid output binding is not available for JavaScript.
786+
Attributes are not supported by Python.
731787

732788
# [Java](#tab/java)
733789

734-
The Event Grid output binding is not available for JavaScript.
790+
The Event Grid output binding is not available for Java.
735791

736792
---
737793

@@ -766,15 +822,15 @@ Send messages by using a method parameter such as `out EventGridEvent paramName`
766822

767823
# [JavaScript](#tab/javascript)
768824

769-
The Event Grid output binding is not available for JavaScript.
825+
Access the output event by using `context.bindings.<name>` where `<name>` is the value specified in the `name` property of *function.json*.
770826

771827
# [Python](#tab/python)
772828

773-
The Event Grid output binding is not available for JavaScript.
829+
The Event Grid output binding is not available for Python.
774830

775831
# [Java](#tab/java)
776832

777-
The Event Grid output binding is not available for JavaScript.
833+
The Event Grid output binding is not available for Java.
778834

779835
---
780836

0 commit comments

Comments
 (0)