Announcement

Collapse
No announcement yet.

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

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

  • 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:	186
Size:	37.3 KB
ID:	94729

  • #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


    • #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.​

      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?

    • #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


      • #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...
        X