Can Before Business Rule, change input for After Business Rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 05:41 AM
Requirement –
On state change, two partners (Say Google & Amazon) API get invoked. With Google API, we are expected to receive more functional errors and Amazon should be successful.
In case Google API gives Functional error, Amazon API should not get invoked.
After Business Rule to invoke Amazon API is already present.
Now we need to establish new integration with Google API.
Purposed Solution:
Write a Before Business Rule to invoke Google API. If response !=200 then current state=previous state and create new GlideRecord object to insert worknote having functional error. This way team will be able to change the state again after fixing the functional error.
This way, in case of Google API failure After Business Rule to invoke Amazon API will not execute, as State change is reverted by Before Business Rule.
Note – Condition to invoke both Business Rule is same.
Before Business Rule to invoke Google API
Invoke Google API.
If response = 200,
Then no action
Else
Current.incident_state = previous.incident_state
Current.update()
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', current.sys_id);
gr.query();
if (gr.next()) {
gr.work_notes = "Transaction failed”;
gr.update();
}
There are existing rules in the application, which does not execute if worknote is also updated.
New GlideRecord object will initiate new transaction to update worknote. This way it will not interfere with previous transaction update where other field e.g. priority, comment might also be modified.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 05:52 AM
Hey @maxpawan2,
In case Google API gives Functional error, Amazon API should not get invoked.
When you are updating the Incident record, you can use:
setWorkflow: Enables and disables the running of business rules and script engines. When disabled, inserts and updates are not audited
Kindly appreciate the efforts of community contributors by marking appropriate response as the correct solution and helpful, this may help other community users to follow the right solution in the future.
Thanks,
Hamza
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:01 AM
Thanks for the quick response. We want after business rule to run as if the user has modified the state, comment, category, and priority then we want to send all updates except the new state change, as it should get reverted to the previous state due to before business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:18 AM
Here I want to community view, whether this approach will take care of our requirements.
Or any alternate suggestion to achieve this requirement.