Announcement

Collapse
No announcement yet.

formula break, exit, return??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • esforim
    commented on 's reply
    Thank you Item, I know I can just chain

    ifthenElse(condition,result,(ifThenElse, condition, result, (ifThenElse...)))

    But it look very messy and not very ideal.
    I also wanted to learn how to use this While feature as well.

    I'm doing formula this for hundreds of City and their Council/Local Government name so it not very ideal chain like that method.

    Currently I'm doing ifThen but it keep using the last currently formula instead of stopping once found.

  • item
    commented on 's reply
    if understand, you don't need the "while"
    i just tested on demo this and this can make your request :

    ifThenElse( assignedUser.userName == null && billingAddressCity == 'Berlin', output\printLine('Empty et Berlin'), output\printLine('NOT Empty'), )

    repeat the ifThen... and not ifThenElse as my sample for all your case

    it's new in formula use "if" like php and not espoCrm Language ?

  • esforim
    commented on 's reply
    Thank you item, would you kindly tell me know I can fix it? I add

    break, break, break in those 3 section.
    Continue, break, break
    Continue, continue, etc combination of these but none seem to work. My logic is no good when it come to coding.

  • item
    commented on 's reply
    break : exit the while
    continue : don’t go next line and continue while, still in while

  • esforim
    replied
    Here is the currently code for Formula Sandbox

    Code:
    output\printLine(addressCity);
    output\printLine(description);
    
    while (description==null) {
        if (addressCity=='City1'||'City2') {
            description='123'; break;
        }
        if (addressCity=='City3'||'City4') {
            description='321'; break;
        }
        // some_final_logic
        
        break; // important
    }
    
    
    // CODE #2024-04-25 end
    output\printLine(addressCity);
    output\printLine(description)
    ​
    When tried with City1
    Click image for larger version  Name:	image.png Views:	0 Size:	2.9 KB ID:	105734

    When tried with City3
    Click image for larger version  Name:	image.png Views:	0 Size:	2.9 KB ID:	105735​​

    Looking at the Documents, I think I am meant to use Continue and break? I tried combination of it and doesn't seem to get the right formula.

    Click image for larger version

Name:	image.png
Views:	94
Size:	14.9 KB
ID:	105736
    Last edited by esforim; 05-04-2024, 04:47 AM.

    Leave a comment:


  • esforim
    commented on 's reply
    Actually now that I'm testing it it just doesn't work correctly... If anyone got tip, appreciated it.

  • esforim
    replied
    EDIT, it does not work correctly! See following post and hopefully solution

    Hi all, finally try this again and I think I figure it out... hopefully it work for you!

    Some note, Property is an address/relationship ID, I only want to run this when it is "null" or "blank".
    AddressCountry is a default address field.

    Code:
    while (propertyId==null) {
        if (addressCountry=='USA') {
            addressCountry ='USB'; break;
        }
        if (addressCountry=='USB') {
            addressCountry ='USC'; break;
        }
        // some_final_logic
    
        break; // important
    }
    
    
    // CODE #2024-04-25 end
    output\printLine(addressCountry);​
    Last edited by esforim; 05-04-2024, 05:09 AM.

    Leave a comment:


  • esforim
    replied
    Update, upon seeing the error above, I went with this formula if anyone want to use it.

    It a very basic formula being use and I don't know if it will always work as I hope it to be... maybe you see an update post some week or months in the future when I run into problem!

    Nothing change except the correct field/attribute (previously I wrote "type" for some reason). So as long as my Status does not equal to "Closed", the formula will executed. When it become Closed it will no longer executed.

    Code:
    //STOP AND DISABLE FORMULA
    if (status!='Closed'){​
    
    // I write my formula here for example:
    description='hey it working'
    
    } // STOP FORMULA DUE TO CLOSE STATUS​
    Last edited by esforim; 04-17-2023, 08:19 AM.

    Leave a comment:


  • esforim
    replied
    Sorry to be a nuisance but is it literally 'break'? Something like this will work?

    I just notice I used 'type!='Closed' in my first post, maybe that why it didnt work.

    Secondly I notice that I have to do this twice when using while formula, would a "if" formula be more ideal?

    Code:
    while (true) {
    if (status!='Open') {
    description='formula is running';
    }
    
    if (status='Closed') {
    description='formula is stop running';
    break;
    }
    
    // some_final_logic
    
    break; // important
    }

    Leave a comment:


  • yuri
    replied
    Code:
    while (true) {
        if (some_condition) {
            break;
        }
    
        if (some_condition) {
            break;
        }
    
        // some_final_logic
    
        break; // important
    }
    ​
    Last edited by yuri; 04-15-2023, 09:11 AM.

    Leave a comment:


  • esforim
    replied
    Hi all, bumping this because I need something like this.

    How do you guy stop the formula from running?

    I want no more formula to run when "Status==Closed", because the Case is closed...

    I see some potential option but I'm not sure if it will work properly and break the formula all together...

    I tried this idea but doesn't seem like it the way to go. Maybe I should use "when"? But not sure how to use the Break part:


    Code:
    //STOP AND DISABLE FORMULA
    if (type!='Closed'){​
    
    write my formula here
    
    } // STOP FORMULA DUE TO CLOSE STATUS

    Leave a comment:


  • item
    replied
    Hello Yuri,
    do you think, as formula is beforeSave and https://github.com/espocrm/documenta...or-handlers.md

    we can just do a global formula ?
    if yes, it's easy to make a new formula.
    if no...

    Kind Regards

    Leave a comment:


  • yuri
    replied
    Hi,

    No such at this moment. Maybe in future.

    Leave a comment:


  • GrokWhy
    started a topic formula break, exit, return??

    formula break, exit, return??

    Hi,

    Is there a way to force an exit on a formula?

    I could nest the code in conditionals, but the code would be simpler if a certain set of conditions were true, stop processing the formula.

    Thanks,
    Russ
Working...
X