Creating Tasks in Espo CRM upon Sales Order Creation

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • esforim
    commented on 's reply
    I think this is the golden ticket!

    Just a discussion/chat; you reckon if there any better "speed" or benefit in using record\fetch method vs record\attribute?

    My brain thinking: record\fetch get everything so it take longer as it try to get all data.
    Whereas record\attribute it take less data because you only get what you ask for.

    Where it might be an issue is it idea of "DDOS".
    (theory speaking here)
    1 record\fetch might take lots of data but it only take 3kb of data
    3 record\attribute might take less data, e.g. 1kb but 3 people try to get the data at once (DDOS)

    That a single user, imagine 100 user, or 1000 user.

  • esforim
    replied
    Originally posted by rabii
    Try this

    PHP Code:
    $i = 0;​ 
    
    Thank you! Will give this a try and maybe finally an update to the learning thread. I'm having trouble with using string\concatenate. Creating a variable from result doesn't help:

    Code:
    $1 = 'concatenante test';
    $i = 0;
    
    while ($i < array\length(contactsIds)) {
    $result = record\attribute('Contact', array\at(contactsIds, $i), 'name');
    $i = $i + 1;
    };
    
    output\printLine($result);
    
    output\printLine(
    string\concatenate($result,' ', $1)
    )​
    Click image for larger version

Name:	image.png
Views:	613
Size:	57.8 KB
ID:	98267​

    Desire result is to be something like this:

    Test Contact 1 concatenate test // result of Array Index 1
    Test Contact 2 concatenate test // result of Array Index 2

    At the moment, I'm guessing I don't it possible to concatenate it.

    Leave a comment:


  • rabii
    replied
    try this, you have to fetch each attribute alone, you can't fetch them all at once:

    PHP Code:
    $i = 0;
    
    while ($i < array\length(contactsIds)) {
        
        $o = record\fetch('Contact', array\at(contactsIds, $i));
    
        if ($o) {
            $name = object\get($o, 'name');
            $firstname = object\get($o, 'firstName');
            $lastname = object\get($o, 'lastName');
            $address = object\get($o, 'address');
        }
        
        output\printLine($name);
        output\printLine($firstname);
        output\printLine($lastname);
        output\printLine($address);
        
        $i = $i + 1;
    }​ 
    

    Leave a comment:


  • esforim
    replied
    Originally posted by rabii
    what do you want to achieve ?
    ​
    Code:
    while ($i < array\length(contactsIds)) {
    output\printLine(record\attribute('Contact', array\at(contactsIds, $i), 'name'));
    output\printLine(record\attribute('Contact', array\at(contactsIds, $i), 'firstName'));​
    output\printLine(record\attribute('Contact', array\at(contactsIds, $i), 'lastName'));​​
    output\printLine(record\attribute('Contact', array\at(contactsIds, $i), 'address'));​​​
    $i = $i + 1;
    }​​
    Basically something like this without having to create one line per field.

    Leave a comment:


  • rabii
    replied
    Try this

    PHP Code:
    $i = 0;
    
    while ($i < array\length(contactsIds)) {
        
        $o = record\fetch('Contact', array\at(contactsIds, $i));
    
        if ($o) {
            $name = object\get($o, 'name');
        }
        
        output\printLine($name);
        
        $i = $i + 1;
    }​ 
    

    Leave a comment:


  • rabii
    commented on 's reply
    what do you want to achieve ?

  • esforim
    replied
    Originally posted by rabii
    Am I being greedy or is there a better way to multiple field/value? Or is the only way is to create record\attribute per field. I'm being 'smart' with these failure of idea:

    ​
    Code:
     $i = 0;
     $m = list('name');
    // https://docs.espocrm.com/administration/formula/record/#recordfetch
    // https://docs.espocrm.com/administration/formula/object/#objectget
    
    while ($i < array\length(contactsIds)) {
        //output\printLine(record\attribute('Contact', array\at(contactsIds, $i), $m)); // error 500
        //output\printLine(record\attribute('Contact', array\at(contactsIds, $i), 'name' && 'name')); // wishful thinking, used name twice because it easier to test formula as oppose to 'firstName'
        output\printLine(record\fetch('Contact', array\at(contactsIds, $i))); // this might be the answer??? but how to combine with if it is object/get()
        $i = $i + 1;
    }​
    Reference:
    // https://docs.espocrm.com/administrat...d/#recordfetch
    // https://docs.espocrm.com/administration/formula/object/#objectget​

    Leave a comment:


  • esforim
    commented on 's reply
    Copy and paste without needing to do anything! Well except for some hidden text in the forum [PHP code] tag I think. It highlight in red so easily fixable after copying.

    THANK YOU.
    Last edited by esforim; 10-04-2023, 11:29 AM.

  • rabii
    replied
    Hey esforim

    First thing you need to initialise the variable $i as an integer with value 0, see code below (that is why array/index give you an error because it is expecting integer but the $i is not defined):

    PHP Code:
    $i = 0;
    
    while ($i < array\length(contactsIds)) {
        output\printLine(record\attribute('Contact', array\at(contactsIds, $i), 'name'));
        output\printLine(contactsIds);
        output\printLine(array\length(contactsIds));
        $i = $i + 1;
    }​ 
    

    I have tested this code on opportunity and it works. Also please notice that record/attribute should have a singular name of the entityType like (Contact) instead of Contacts.

    I hope this helps
    Last edited by rabii; 10-04-2023, 10:49 AM.

    Leave a comment:


  • esforim
    replied
    rabii Finally got a chance to play with this formula, would you be able to help? I don't know where I'm doing it wrong. It telling me it should be a int, but formula I reference: Post #3 and it should be correct. I obviously doing something wrong because copy/paste of your formula work fine.

    Copy of formula:
    Click image for larger version

Name:	image.png
Views:	559
Size:	13.1 KB
ID:	98215​

    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


    Click image for larger version

Name:	image.png
Views:	595
Size:	19.3 KB
ID:	98213​

    It cannot read the "$i", if I put a number manually it seem to work.

    Click image for larger version

Name:	image.png
Views:	551
Size:	23.8 KB
ID:	98214​

    Leave a comment:


  • esforim
    commented on 's reply
    Thank you. Will give this a try to upgrade my formula level

  • rabii
    replied
    Yeah esforim

    The idea is that $i will be initialed with 0 and the while loop will keep executing while condition is true. e.g below formula for opportunity that has contacts you can use while in sandbox:

    PHP Code:
    while ($i < array\length(contactsIds)) {
        output\printLine('Looping...');
        output\printLine($i);
        $i = $i + 1;
    }​ 
    

    Leave a comment:


  • esforim
    commented on 's reply
    Need to scroll through forum for more $i and while forum. Can't wrap my head around how to use this. I understand it some sort of +1 counter and keep doing this until it count no more?

  • rabii
    commented on 's reply
    got it
    yeah i like the new syntax for existing function like (while - if etc...)
    I have seen that you added a record\findMany which is very useful (will take it out of my custom functions now) hope you will consider entity\setAttributes(ATT1, VALUE1, ATT2, VALUE2...) this is very useful when trying to set multiple attributes of a record. been using it as a custom function and helped a lot.

    thanks

  • yuri
    commented on 's reply
    No way to define functions (within formula). Just an example.

    The new "while" is the same as in many programming languages.
Working...