Can Before Business Rule, change input for After Business Rule?

maxpawan2
Tera Contributor

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.

3 REPLIES 3

Muhammad Hamza
Kilo Sage

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:

gr.setWorkflow(false); before updating the record
Here, we set workflows running to False, so no business rules will run, making sure that Amazon After BR does not run.

 

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

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. 

maxpawan2
Tera Contributor

Here I want to community view, whether this approach will take care of our requirements.

Or any alternate suggestion to achieve this requirement.