Announcement

Collapse
No announcement yet.

Error "Can't use an entity w/o ID" in API Before Save Script

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

  • Error "Can't use an entity w/o ID" in API Before Save Script

    Hello,

    I am working on an API Before Save Script where I check the value of an attribute to determine whether the entity can be saved or not. The script works perfectly when the entity is updated, but I encounter the following error when trying to save a new entity:

    "Can't use an entity w/o ID."

    It seems like the script is trying to use the ID of the entity, which doesn't exist for new records. How can I modify the script to handle new entities (without IDs) and still enforce the logic based on the attribute value?

    Thank you in advance for your help!

  • #2
    HI,

    It can take time to try to figure out what your failing script is doing. A provided non-working snippet would make it easier.​

    Comment


    • alohatech
      alohatech commented
      Editing a comment
      Hello yuri , This my code:
      if (attributeA!="A"){

      if (programme.name=="P0001"){
      $message = "modification is disabled.";



      recordService\throwBadRequest($message);

      }
      }

  • #3
    Hello This the used code :
    PHP Code:
    if (attributeA != "A") {

        if (
    programme.name == "P0001") {
            
    $message "modification is disabled.";



            
    recordServicethrowBadRequest($message);

        }
    }
    ​ 

    Comment


    • #4
      Hi,

      Related attributes are not available in API before-save script when the record is new.

      Click image for larger version  Name:	image.png Views:	0 Size:	14.8 KB ID:	111683

      Comment

      Working...
      X