Creating Tasks in Espo CRM upon Sales Order Creation
Collapse
X
-
I encourage all to use the new while syntax instead of old one.
Good:
Bad:Code:while ($i < $length) { doSomething(); $i = $i + 1; }
Code:while( $i < $length, ( doSomething(); $i = $i + 1; ) ); -
hey @yubrajkafle,
As lazovic explained this could be achieve using formula, however i noticed in your comment that you want each task to be related to each sales order item, by default there no link between the two entities, in order to achieve this you need to do the steps below:
1 - Go to Administration > Entity Manager > Task > Fields (access parent field and add the sales order item to the list)
2 - Go to Administration > Entity Manager > Task > Relationships (Edit Children-to-Parent and check the sales order item as foreign link)
3 - Go to Administration > Entity Manager > Sales Order Item > Layout > Bottom Panels (Add the Task panel to be displayed on the bottom panel by dragging the Task from disabled to enabled)
Now you are done with the steps above, the task will have Sales Order Item as a parent and also Sales Order Item will have a Task panel on the detail view, you can now follow the steps provide by lazovic to achieve this, one addition i would add there is as below :
PHP Code:// inject count automatically to cover all items $count = entity\countRelated('items'); $itemsIds = record\findRelatedMany('SalesOrder', id, 'items', $count); $i = 0; while( $i < array\length($itemsIds), ( record\create( 'Task', 'parentId', array\at($itemsIds, $i), 'parentName', 'Sales Order Item', 'name', record\attribute('SalesOrderItem', array\at($itemsIds, $i), 'name'), 'assignedUserId', '1' // insert the ID of the specific user ); $i = $i + 1; ) );
Using while new syntax
Hope this helpsPHP Code:// inject count automatically to cover all items $count = entity\countRelated('items'); $itemsIds = record\findRelatedMany('SalesOrder', id, 'items', $count); $i = 0; while($i < array\length($itemsIds)) { record\create( 'Task', 'parentId', array\at($itemsIds, $i), 'parentName', 'Sales Order Item', 'name', record\attribute('SalesOrderItem', array\at($itemsIds, $i), 'name'), 'assignedUserId', '1' // insert the ID of the specific user ); $i = $i + 1; }Last edited by rabii; 06-30-2023, 01:04 PM.Leave a comment:
-
Hi sapyantuk,
To achieve this functionality, you should create a Workflow with:- Target Entity: Sales Order
- Trigger Type: After record created
- Action: Execute Formula Script (insert the formula below)
This formula script can be supplemented by adding certain fields to the created Tasks. You can describe in more detail how the Tasks should look like, so that I can finalize this formula script for you.Code:$itemsIDs = record\findRelatedMany('SalesOrder', id, 'items', 1000); $i = 0; while( $i < array\length($itemsIDs), ( record\create( 'Task', 'name', record\attribute('SalesOrderItem', array\at($itemsIDs, $i), 'name'), 'assignedUserId', '1' // instaed of 1 insert the ID of the specific user ); $i = $i + 1; ) );Last edited by lazovic; 06-30-2023, 07:47 AM.Leave a comment:
-
Creating Tasks in Espo CRM upon Sales Order Creation
Hello team,
I hope this message finds you well. I am currently using Espo CRM with the Sales Pack and Advance Pack extensions. I have encountered a requirement where I need to create a task in the system whenever a sales order is created
To clarify, when we receive a new order and create a sales order in the system, I would like to automatically generate a task associated with that order items . Furthermore, if the sales order contains multiple items, I would like to create multiple tasks accordingly.
The tasks should be assigned to a specific user within the system. Could you please guide me on how to implement this functionality within Espo CRM?
Thank you for your assistance.
Tags: None

Leave a comment: