tanya GOOD NEWS!
The "issue" was that we didn't create the ContainsType.php to begin with <?php tag (I know, silly mistake).
Now it is working PERFECTLY! This is the final ContainsType.php
Thanks a LOT for your patience, time and knowledge.
You have saved us!
Best regards.
Announcement
Collapse
No announcement yet.
IfThenElse Inside IfThenElse Formula?
Collapse
X
-
Permission for ContainsType.php file is 644.
Should we change it to 777?
Thanks.
Leave a comment:
-
Hi tanya
We see the following error in data/logs
[2017-04-20 14:19:43] Espo.ERROR: Formula failed: Class \Espo\Core\Formula\Functions\StringGroup\ContainsT ype was not found. [] []
Strange. We are using the same code in ContainsType and it's located in application/Espo/Core/Formula/Functions/StringGroup. You can see the ContainsType file we are using here.
What can it be?
Thanks a lot.
Leave a comment:
-
Yes, we are talking about formula
Code:ifThenElse(string\contains(name, 'sort'), description='RESORT', description='NOSORT');
Your example works as well (ifThenElse(string\contains(name, 'Product A'), description = 'Product A') Check data/logs
Leave a comment:
-
Hi tanya
This is very frustrating. We haven't been able to set it up- Are you using the formula in the entity manager or the workflow module?
- We are trying to keep things simple for now. We are using the new formula (string\\contains(HAYSTACK, NEEDLE, OFFSET)) for cases. If we use the following formula it doesn't work:
Code:ifThenElse(string\contains(name, 'Product A'), description = 'Product A');
- If we use the following formula it will set description as 'Product A' with ANY text used in name:
Code:ifThenElse(string\contains(name, 'Product A') = true, description = 'Product A');
Thanks again for your valuable time.
Leave a comment:
-
TRUE/FALSE result
return !(strpos($haystack, $needle) === false);
for me it works. I tested
Leave a comment:
-
Hi tanya ,
We used your formula but it didn't work.
Just to be clear, what is the result of the formula string\contains? Will it return the numeric position of where the NEEDLE exists relative to the beginning of the HAYSTACK string? Or is it just a TRUE/FALSE result?
Thanks.
Leave a comment:
-
ifThenElse(
string\contains(name, 'Product A'),
product = 'Product A'
ifThen(
string\contains(name, 'Product B'),
product = 'Product B')
);
Leave a comment:
-
Awesome! Thanks tanya
We followed your instructions and see the formula string\\contains(HAYSTACK, NEEDLE, OFFSET)
Can you please specify what does each "section" (HAYSTACK, NEEDLE, OFFSET) represent?
How would our final formula be?
ifThenElse(
string\contains(HAYSTACK, NEEDLE, OFFSET) = 'Product A',
product = 'Product A'
ifThen(
string\contains(HAYSTACK, NEEDLE, OFFSET) = 'Product B',
product = 'Product B')
);
Thanks A LOT.
Leave a comment:
-
I didn't note, contains search mode is not supported for workflows.... sorry
you can add this function to formula
Create application/Espo/Core/Formula/Functions/StringGroup/ContainsType.php with code
Code:namespace Espo\Core\Formula\Functions\StringGroup; use \Espo\Core\Exceptions\Error; class ContainsType extends \Espo\Core\Formula\Functions\Base { public function process(\StdClass $item) { if (!property_exists($item, 'value')) { throw new Error(); } if (!is_array($item->value)) { throw new Error(); } if (count($item->value) < 2) { throw new Error(); } $haystack = $this->evaluate($item->value[0]); $needle = $this->evaluate($item->value[1]); if (count($item->value) > 2) { $offset = $this->evaluate($item->value[2]); return !(strpos($haystack, $needle, $offset) === false); } else { return !(strpos($haystack, $needle) === false); } } }
How to use:
string\contains(HAYSTACK, NEEDLE, OFFSET)Last edited by yuri; 04-18-2017, 02:50 PM.
Leave a comment:
-
Hello
string\\substring(STRING, START, LENGTH) Extracts the characters from a STRING by START position and LENGTH.
If LENGTH is omitted, the substring starting from START until the end of the STRING will be returned.
If LENGTH is negative, then that many characters will be omitted from the end of STRING.string\substring(name, 1) = '*Product A*',
or develop baforeSave hook for your entity (on the forum exist a lot of examples)
Leave a comment:
-
IfThenElse Inside IfThenElse Formula?
Hi,
We have been trying to use formulas for cases with the following criterias:
* If string name contains "Product A", set field product to "Product A"
* If string name contains "Product B", set field product to "Product B"
* If string name contains "Product C", set field product to "Product C"
* If string name contains "Product D", set field product to "Product D"
We have been testing A LOT of formulas but haven't been able to work it. We have the following for the first two criterias using wild cards:
ifThenElse(
string\substring(name, 1) = '*Product A*',
product = 'Product A'
ifThen(
string\substring(name, 1) = '*Product B*',
product = 'Product B')
);
Are we in the right track? What are we missing?
Thanks a lot and hope to hear from you.
Tags: None
Leave a comment: