Creating Tasks in Espo CRM upon Sales Order Creation

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • rabii
    commented on 's reply
    started using it but just when offering code for other i use the old one because i am not sure which version they have. doSomething() is there a way in formula to define a function and call it like that ?

  • yuri
    replied
    I encourage all to use the new while syntax instead of old one.


    Good:
    Code:
    while ($i < $length) {
        doSomething();
      
        $i = $i + 1;
    }
    Bad:
    Code:
    while(
        $i < $length,
        (
            doSomething();
            $i = $i + 1;
        )
    );​  ​
    ​

    Leave a comment:


  • rabii
    commented on 's reply
    you are welcome mate

  • lazovic
    commented on 's reply
    Thanks for your additions.

  • rabii
    replied
    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

    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;
    }​ 
    
    Hope this helps
    Last edited by rabii; 06-30-2023, 01:04 PM.

    Leave a comment:


  • lazovic
    replied
    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)
    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;
        )
    );
    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.
    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.
    ​
Working...