Unknown function recordService\throwForbidden when used with Before-save formula

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • william34
    Junior Member
    • Jun 2023
    • 21

    Unknown function recordService\throwForbidden when used with Before-save formula

    Hi,

    I am using an formula to check if 'website' url contains @ or / character. I want to raise error if this character is found in url.

    I am getting error in log file when using formula as recordService/forbidden is not function.

    PHP Code:
    
    $site = website;
    
    if (string\contains($site, '@') || string\contains($site, '/')){
        //throw exception as not allowed to user.
        
        recordService\throwForbidden('Error url contain @ , /');
    }

    Click image for larger version

Name:	image.png
Views:	198
Size:	37.3 KB
ID:	94729
  • ThomasB
    Senior Member
    • Mar 2022
    • 163

    #2
    If I look at https://docs.espocrm.com/administrat...throwforbidden

    it looks like you need to use " instead of '

    recordService\throwForbidden("Not allowed to change status.");​

    Comment

    • yuri
      Member
      • Mar 2014
      • 8454

      #3
      Hi,

      See https://docs.espocrm.com/administrat...cial-functions

      These functions are available only in API Before-Save Script. Using them in other places will produce an error.​
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment


      • william34
        william34 commented
        Editing a comment
        Hi yuri,

        I am using it in Lead formula . Which is in website at
        Admin > Entity Manger > Lead > Formula.

        Is Lead formula Before-Save script?
    • ThomasB
      Senior Member
      • Mar 2022
      • 163

      #4
      Which version of EspoCRM are you using? You need at least version 7.5.x

      Admin > Entity Manger > Lead > Formula -> API Before-Save Script


      If you click on Formular you should have two options: Before Save Custom Script and API Before-Save Script.​

      Comment

      • william34
        Junior Member
        • Jun 2023
        • 21

        #5
        It was on version 7.4.5

        Version 7.5 is required. Upgraded and now it available.



        Thank you, ThomasB​ and yuri​.
        You have been a great help. ?

        Comment

        Working...