Hi all,
I had added a custom button in CombinedModeActionButtonsCardLeftContainer
{
"operation": "insert",
"parentName": "CombinedModeActionButtonsCardLeftContainer",
"propertyName": "items",
"name": "ClearReceiptButton",
"values": {
"itemType": Terrasoft.ViewItemType.BUTTON,
"caption": { "bindTo": "Resources.Strings.MakeClearReceiptButtonCaption" },
"enabled": { "bindTo": "canClearReceipt" },
"visible": { "bindTo": "isUnclearReceipt" },
"click": { "bindTo": "onClearReceiptClick" },
"layout": {
"column": 1,
"row": 6,
"colSpan": 1
}
}
}
and methods
onClearReceiptClick: function() {
var message = this.get("Resources.Strings.ClearReceiptConfirmMessage");
var me = this;
var activeRow = this.get("ActiveRow");
if (!activeRow) {
return false;
}
var selectedRow = me.get("GridData").get(activeRow);
if (selectedRow.get("DsslmContract") === undefined ||
selectedRow.get("DsslmContract") === null ||
selectedRow.get("DsslmContract") === "")
{
Terrasoft.showMessage(this.get("Resources.Strings.InputContractMessage"));
return;
}
Terrasoft.showConfirmation(message, function(result) {
if (result === Terrasoft.MessageBoxButtons.YES.returnCode) {
var id = selectedRow.get("Id");
var contractId = selectedRow.get("DsslmContract").value;
var args = {
// Process name
sysProcessName: "DsslmProcessUpdateUnclearReceiptToClear",
// parameters process
parameters: {
UnclearReceiptId: id,
ContractId: contractId
}
};
// run process
ProcessModuleUtilities.executeProcess(args);
}
}, ["yes", "no"], this);
},
isUnclearReceipt: function() {
var activeRow = this.get("ActiveRow");
if (!activeRow) {
return false;
}
var selectedRow = this.get("GridData").get(activeRow);
return selectedRow.get("DsslmStatus").value === "a74e5706-d659-4841-b5b0-e8bfccd21065";
},
canClearReceipt: function() {
var activeRow = this.get("ActiveRow");
if (!activeRow) {
return false;
}
var selectedRow = this.get("GridData").get(activeRow);
return selectedRow.get("DsslmContract") !== undefined &&
selectedRow.get("DsslmContract") !== null &&
selectedRow.get("DsslmContract") !== "";
}
If I change value of column "DsslmContract" and click that button the "selectedRow.get("DsslmContract")" will get the old value.
Like
Toan Mai,
Yes, enabled/visible aren't quite as nice, and it took a bit of digging through vanilla Creatio code to figure out how to make it work for those as well, but essentially what you should have is an attribute on both the Edit Page and Section schemas with the same name which the button's enabled/visible property are bound to (in both schemas) and then in the Edit Page schema have the onChange property of the attribute set to some method which will look something like the following:
attributes: { "CustomAttributeName": { dataValueType: Terrasoft.DataValueType.BOOLEAN, onChange: "onCustomAttributeNameChange" } }, methods: { onCustomAttributeNameChange: function(model, value) { this.publishPropertyValueToSection("CustomAttributeName", value); } }
This causes the attribute on the Edit Page to be sent to the Section schema whenever it's changed in the Edit Page, updating the attribute on the Section schema, which means the button will have the same visibility/enabled behaviour on both the regular edit page and the Combined mode view.
Dear Toan,
An edit page can be seen in two different modes, (1) edit mode (where you're only displaying the edit page, this is what you're getting when you refresh the page while in edit mode) and (2) combined mode, this is actually the section page, where it displays the context of the section list you were on with the edit page on the side.
In combined mode, values for fields from the active record are taken from the registry. Please see the screenshot below:
When you change the value of a field on the edit page, but don’t save the changes (do not click the “Save” button), the value for the field does not change in the registry. Therefore, when you try to get the value of this field in the code, you get the old value.
Please keep this in mind when further developing custom logic.
Best regards,
Norton
Toan, you might find letting the edit page handle Combined Mode buttons' functionality would work better for you than duplicating logic in both the edit page schema and the section list schema - this can be achieved by specifying the "click" property of the button to be onCardAction, and adding a "tag" property to the button with the name of the method on the edit page schema that should be run when the button is clicked. In your button's case this would look something like this:
{ "operation": "insert", "parentName": "CombinedModeActionButtonsCardLeftContainer", "propertyName": "items", "name": "ClearReceiptButton", "values": { "itemType": Terrasoft.ViewItemType.BUTTON, "caption": { "bindTo": "Resources.Strings.MakeClearReceiptButtonCaption" }, "enabled": { "bindTo": "canClearReceipt" }, "visible": { "bindTo": "isUnclearReceipt" }, "click": { "bindTo": "onCardAction" }, "layout": { "column": 1, "row": 6, "colSpan": 1 }, "tag": "onClearReceiptClick" // <- this method will be run on the edit page when the button is clicked in combined mode } }
Harvey Adcock,
That's a fantastic idea, thanks for that tip Harvey.
Ryan
Harvey Adcock,
I knew that solution, but I can't bind "enabled" with field value by function getting, because it's always old value. If there is only one field need to check I can show error message before execute, but possible if there are many fields to check.
Toan Mai
Toan Mai,
Yes, enabled/visible aren't quite as nice, and it took a bit of digging through vanilla Creatio code to figure out how to make it work for those as well, but essentially what you should have is an attribute on both the Edit Page and Section schemas with the same name which the button's enabled/visible property are bound to (in both schemas) and then in the Edit Page schema have the onChange property of the attribute set to some method which will look something like the following:
attributes: { "CustomAttributeName": { dataValueType: Terrasoft.DataValueType.BOOLEAN, onChange: "onCustomAttributeNameChange" } }, methods: { onCustomAttributeNameChange: function(model, value) { this.publishPropertyValueToSection("CustomAttributeName", value); } }
This causes the attribute on the Edit Page to be sent to the Section schema whenever it's changed in the Edit Page, updating the attribute on the Section schema, which means the button will have the same visibility/enabled behaviour on both the regular edit page and the Combined mode view.