Using JavaScript to loop a command
Inserting and updating multiple rows into the database table.
insert into Subscriptions(UserId,ChannelId,SubscriptionCost)
values(:UserId,:ChannelId,:SubscriptionCost)
CheckboxSet onChange event
// For handling Selected Channels
var userChannels = [];
Page.checkboxsetSelectedChannelsChange = function ($event, widget, newVal, oldVal) {
// Selected Channels are added
userChannels = newVal;
};
Loop function through JavaScript
Page.buttonSubscribeClick = function ($event, widget) {
// Check if User selected any channels if YES add them ELSE notify him
if (userChannels.length > 0) {
// Iterating along the selected channels for subscription and adding them
for (let i = 0; i < userChannels.length; i++) {
Page.Variables.AddSubscriptions.setInput({
"UserId": Page.Widgets.selectSelectUser.datavalue,
"ChannelId": userChannels[i],
"SubscriptionCost": "10$"
});
Page.Variables.AddSubscriptions.invoke();
}
} else
Page.Actions.SelectionNotifier.notify();
};
See Also
How to use JavaScript to Use Expressions for Binding
How to load JavaScript from external URLs
How-To insert/update multiple rows in a database using a FOR loop in JavaScript