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.
Creating Tasks in Espo CRM upon Sales Order Creation
Collapse
X
-
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) )
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. -
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:
-
Basically something like this without having to create one line per field.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; }Leave a comment:
-
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:
-
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:Hey esforim
Reference: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; }
// https://docs.espocrm.com/administrat...d/#recordfetch
// https://docs.espocrm.com/administration/formula/object/#objectgetLeave a comment:
-
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:
-
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:
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
It cannot read the "$i", if I put a number manually it seem to work.
Leave a comment:
-
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:
-
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
Leave a comment: