workflow help on relations Many-to-One and One-to-Many.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nishan Perera
    Active Community Member
    • Jan 2019
    • 348

    workflow help on relations Many-to-One and One-to-Many.

    Hello,

    I'm want to link single record from relation entity which created At current month. For every month there will be one new record in entity stock. Below screenshot is Entity Items and its related to stock

    relations is used Many-to-One and One-to-Many.

    Any help to create workflow to this


    Click image for larger version

Name:	items screen.PNG
Views:	402
Size:	47.1 KB
ID:	67011

    Cheers!
    Nishan.
  • Maximus
    Senior Member
    • Nov 2018
    • 2731

    #2
    Hi Nishan,
    It is not clear. Could you describe it more detailed?
    Thanks.

    Comment

    • Nishan Perera
      Active Community Member
      • Jan 2019
      • 348

      #3
      Hi Maximus ,

      In this interface I wanted to update "Stock" field with the related stock record which is created on current month.

      Example-
      if current month January
      Stock = Pack, January 2021

      if current month February
      Stock = Pack, February 2021


      Every month Stock field should change with the current month stock record. Only one record will create for every month for each item.

      Cheers!
      Nishan.

      Comment

      • Maximus
        Senior Member
        • Nov 2018
        • 2731

        #4
        This makes sense.
        Well, I see it with this way.
        1. Create a Workflow for the target record:
        - Trigger type: After record creation
        - Action: Update target record -> you will need to write a huge formula here
        2. How I see it:
        Code:
        // Determine the month of the createdAt field and convert it to a raw format. E.g.:
        
        $month = '';
        $year = datetime\year(createdAt);
        $stockName = ''
        ifThen(
            datetime\month(createdAt) == 1,
            $month = 'January';
            $stockName = string\concatenate("Pack, ", $month, " ", $year)
        );
        ifThen(
            datetime\month(createdAt) == 2,
            $month = 'February';
            $stockName = string\concatenate("Pack, ", $month, " ", $year)
        );
        //Other condition to determine the rest months.
        ....
        
        // Fetch ID of the Stock record with this formula https://docs.espocrm.com/administration/formula/#recordfindone. E.g.:
        
        $id = record\findOne('Stock', 'createdAt', 'desc', 'name=', $stockName);
        
        // Link the target record with to a Stock.
        
        stockId = $id;

        Comment

        Working...