I am an absolute newby to JavaScript and I am trying to change the value of column ZEILE_STATUS to ‘T0’ if a new entry is made in the grid and the value of this column to ‘T’ for all the following rows which do not have an entry. This is what I have tried(the above code is for another functionality which does not count for my problem now)
function customIgAction(config) {
var $ = apex.jQuery,
toolbarData = $.apex.interactiveGrid.copyDefaultToolbar(),
toolbarGroup = toolbarData.toolbarFind("actions3"); // This is the group with the actions menu
// Add a copy-down button after the actions menu
toolbarGroup.controls.push({
type: "BUTTON",
action: "selection-copy-down",
icon: "icon-ig-copy-down",
label: "Nach unten kopieren",
iconBeforeLabel: true,
iconOnly: false
});
// Customize Save Button
var saveButton = toolbarData.toolbarFind("save");
if (saveButton) {
saveButton.icon = "icon-ig-save";
saveButton.iconBeforeLabel = true;
saveButton.iconOnly = false;
}
// Customize Edit Button
var editButton = toolbarData.toolbarFind("edit");
if (editButton) {
editButton.icon = "icon-ig-edit";
editButton.iconBeforeLabel = true;
editButton.iconOnly = false;
}
config.toolbarData = toolbarData;
// Customize actions
config.initActions = function(actions) {
actions.hide("show-aggregate-dialog");
actions.hide("show-filter-dialog");
actions.lookup("save").shortcut = "Ctrl+Alt+S";
actions.update("save");
// Add "pause-ein" action
actions.add({
name: "pause-ein",
label: "Pause eintragen",
shortcut: "Ctrl+Alt+P",
action: function(event, focusElement) {
let view = apex.region("ZEITERF").widget().interactiveGrid("getCurrentView");
if (view.supports.edit) {
let model = view.model;
let record = view.getContextRecord(focusElement)[0];
// Set values for the current record
model.setValue(record, "ZEILE_STATUS", "P");
model.setValue(record, "AB_KZL", "");
model.setValue(record, "KUN", "");
model.setValue(record, "TA_ID", "");
model.setValue(record, "PA_ID", "");
model.setValue(record, "TA_PROTT", "");
apex.message.showPageSuccess("pause successfully entered!");
}
}
});
// Add "pause-raus" action
actions.add({
name: "pause-raus",
label: "Pause rausnehmen",
action: function(event, focusElement) {
alert("make pause back to T!");
}
});
// Add "pause-deaktiviert" action
actions.add({
name: "pause-deaktiviert",
label: "Abwesend",
action: function(event, focusElement) {
alert("not possible");
}
});
// Add logic for new row entry
let view = apex.region("ZEITERF").widget().interactiveGrid("getCurrentView");
let model = view.model;
model.subscribe("modelCreate", function(event, record) {
// Set the new record's ZEILE_STATUS to 'T0'
model.setValue(record, "ZEILE_STATUS", "T0");
// Get all rows and update subsequent rows to 'T'
let records = model.getRecords();
let foundNewEntry = false;
records.forEach(function(row) {
if (model.getValue(row, "ZEILE_STATUS") === "T0") {
foundNewEntry = true;
} else if (foundNewEntry) {
model.setValue(row, "ZEILE_STATUS", "T");
}
});
});
};
return config;
}
I have just added the code for Add logic for new row entry ‘Add logic for new row entry’ the other code is from another developer who made the first steps. But now I need to reach out for getting the values changed. And I already do not have more ideas. Anybody can help me?
Thanks Irina
I have checked all the static IDs and there is no mistake but I am getting all the time the error:
TypeError: apex.region(...).widget() is null
But before I have added my part of code it worked.