Can't set the table or Conditions in Business rule API

pedrams
Tera Expert

Trying to use this API: https://www.servicenow.com/docs/bundle/xanadu-application-development/page/build/servicenow-sdk/refe...

 

 

I can create a business rule no problem using this json body: 

 

```

{
"name": "XXXXXX",
"table": "incident",
"when": "after",
"action": ["insert", "update", "delete"],
"active": true,
"condition": "true",
"script": "XXXXXXXX"
}

```

 

but the table and actions are not set. 

 

Screenshot 2025-01-21 at 5.52.08 PM.png

1 ACCEPTED SOLUTION

pedrams
Tera Expert

The API documentation is wrong, the correct way to set the table is to use the "collection" field and the correct way to set the actions are to append a prefix of "action_" and it is not an array of actions, it's a string!

so 

 

{
  "name": "XXXXXX",
  "collection": "incident",
  "when": "after",
  "action_insert": "true",
	"action_update": "true",
	"action_query": "true",
	"action_delete": "true",
  "active": true,
  "condition": "true",
  "script": "XXXXX"
}

 

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@pedrams 

but why to create BR using API?

Not a good practice

I don't think it's a valid business requirement to create BR via API

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

There is a valid reason and there is an API with clear documentation so why not!

The question is why is the API not working as documented. Is it a user error somewhere or an API bug. 

Why is it not a good practice? Either case my use case requires it. I just need to know why it's not working, and what the issue is here. 

pedrams
Tera Expert

The API documentation is wrong, the correct way to set the table is to use the "collection" field and the correct way to set the actions are to append a prefix of "action_" and it is not an array of actions, it's a string!

so 

 

{
  "name": "XXXXXX",
  "collection": "incident",
  "when": "after",
  "action_insert": "true",
	"action_update": "true",
	"action_query": "true",
	"action_delete": "true",
  "active": true,
  "condition": "true",
  "script": "XXXXX"
}