Hi community,
I have a list of warehouses that contains the "Primary" field. It's only one of them that can be a primary warehouse.
When a user creates an order, I want the "Warehouse" field can be set automatically to the primary warehouse.
How to do this?
Thank you.
Like
I has solved this problem by adding parameter "this" into the "result.collection.each()".
It will be shown as "result.collection.each(function(), this)"
esq.getEntityCollection(function(result) { debugger; if (!result.success) { // For example, error processing/logging. this.showInformationDialog("Can't set the location."); return; } result.collection.each(function(item) { var primaryWarehouse = {value: item.get("Id"), displayValue: item.get("SceName")}; this.set("SceWarehouse", primaryWarehouse); return; }, this) }, this);
You can Use Business Rule for auto populating Some fields.
https:/academy.creatio.com/docs/user/customization_tools/ui_and_business_logic_customization/business_logic/setup/set_up_a_new_business_rule
Hi smit suthar,
I have tried to use the "Set field value" action, but it's too simple.
I want to set the value of "Warehouse" with a primary warehouse.
Note: The "Warehouse" section has the "Primary" (boolean) field.
So, for example; I have 2 warehouses, "A" and "B". And, I set the warehouse "B" primary field as TRUE. Then, when the user creates an order, the "Warehouse" field of the order will be filled by "B" automatically.
Do you have any other ideas?
Hello David Chandra,
Based on the shared information I can assume that your business task can be fully covered with a help of business rules functionality.
If you'd like to expand the customization you can consider designing the custom business process that will read the needed columns from a page and apply changes with a Modify data element or even with script-task element where you can specify the custom logic with code.
Alternatively, you can implement your business task with a help of additional development, but we do not have a specific ready to use example of such implementation.
Best regards,
Anastasiia
Hello Anastasiia,
If we use the Business Rule means, we have to save the order and then use "added data trigger" to set the warehouse value.
Do you know how to set the warehouse value before we save the new order?
Regards,
David
Hello Anastasiia,
I managed to create a function in the page source code as below:
/* Overload the base Terrasoft.BasePageV2.onEntityInitialized method that is called after Creatio initializes the schema of the record page object. */ onEntityInitialized: function() { /* Call the parent implementation of the method. */ this.callParent(arguments); /* Call the handler method that sets the [Location] column value. */ this.setWarehouse(); }, /* The handler method that sets the [Warehouse] column value. */ setWarehouse: function() { /* The [Warehouse] column value. */ var location = this.get("SceWarehouse"); /* Checks whether the mode of the new record is set. */ var newmode = this.isNewMode(); // * If the value is not set and the mode of the new record is set. */ if (!location && newmode) { /* Get the contact's location by using ESQ */ const userContactId = Terrasoft.SysValue.CURRENT_USER_CONTACT.value; const esq = this.Ext.create(Terrasoft.EntitySchemaQuery, { rootSchemaName: "SceWarehouse" }); esq.addColumn("Id"); esq.addColumn("SceName"); esq.addColumn("Primary"); const esqFirstFilter = esq.createColumnFilterWithParameter(Terrasoft.ComparisonType.EQUAL, "Primary", true); esq.filters.add("esqFirstFilter", esqFirstFilter); esq.getEntityCollection(function(result) { debugger; if (!result.success) { // For example, error processing/logging. this.showInformationDialog("Can't set the location."); return; } result.collection.each(function(item) { var primaryWarehouse = item; this.showInformationDialog(primaryWarehouse.get("SceName")); this.set("SceWarehouse", primaryWarehouse); }) }, this); } }
The "showInformationDialog" function is able to show the correct record.
But, the "SceWarehouse" is still not populated.
Note: "SceWarehouse" field is a lookup based on the "SceWarehouse" section.
Could you help?
Thank you.
I has solved this problem by adding parameter "this" into the "result.collection.each()".
It will be shown as "result.collection.each(function(), this)"
esq.getEntityCollection(function(result) { debugger; if (!result.success) { // For example, error processing/logging. this.showInformationDialog("Can't set the location."); return; } result.collection.each(function(item) { var primaryWarehouse = {value: item.get("Id"), displayValue: item.get("SceName")}; this.set("SceWarehouse", primaryWarehouse); return; }, this) }, this);