The CreatorCon Call for Content is officially open! Get started here.

Can't Close a CR Because of a Business Rule Stack:Change Model: Check State Transition

clerambeau3
Kilo Contributor

Hi. I am new to SN. I am running an Ansible automation playbook. It connects from a remote host via an API. The playbook is straightforward.  

1) Create a change request. Cache its number in memory for subsequent steps to re-use.

2) Close the change request.

The creation works fine.  But the closure does not. 

Here is the error:

TASK [Close the CR CHG0030100 after a successful execution on 2025-10-22T00:36:00Z] **********************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => changed=false 
  msg: 'Unexpected response - 403 b''{"error":{"message":"Operation Failed","detail":"Operation against file \''change_request\'' was aborted by Business Rule \''Change Model: Check State Transition^b71e12a083f0b210f28198c6feaad3e3\''. Business Rule Stack:Change Model: Check State Transition"},"status":"failure"}'''

So, it appears I am violating some business rule. There is another thread here that has a solution, but it is as clear as mud to me. I am a database admin, not a ServiceNow professional. Can you help me with an exact, step-by-step instructions listed here:

Why does the Change model not allow state transitions in normal change workflow? 

Here is the part in the SN manual that seems relevant:

Configure state model transitions 

This is not an Ansible or automation problem for two reasons:

1) The automation successfully creates the CR. We know that because it actually announces its number, before attempting to close it. I can also see it in my PDI URL.

2) The error coming from ServiceNow clearly indicate it is a business rule that is the reason:

clerambeau3_0-1761094370033.png

So, my question is how do I bypass the rule within ServiceNow? Keep in mind this is a PDI and I can disable or change any rules there. It is all for demo purposes. Alternatively, if I need to add more steps to the playbook (attached) to get to the point where I will be ALLOWED to close it, that isnt a problem. I just need to know what additional steps I need to automate for the given CR number, between the creation and the closure. If you can, please post step by step screenshots, otherwise I will be lost in SN terms and features I know nothing about.

Thank you.

Nestor.

 

Ansible playbook:

---
    - name: Omni-Vendor Omni-Environment Emergency Password Rotation Process ID 2972.56 
      hosts: localhost
      gather_facts: true
      vars_files:
        - vars/main.yml

      tasks:

      - name: Create main change request on {{ ansible_date_time.iso8601 }} 
        servicenow.itsm.change_request:
          instance:
            host: "{{ sn_instance}}"
            username: "{{ sn_username }}"
            password:  "{{ sn_password }}"
          type: standard
          state: new
          requested_by: admin
          short_description: Oracle OCI Password Rotation CR Triggered by INC {{ ansible_date_time.iso8601 }}   
          description: Emergency Vault passwords rotation for Oracle OCI Event Incident on {{ ansible_date_time.iso8601 }} 
          attachments:
            - path: /tmp/refresh_task_sid.txt
          priority: moderate
          risk: low
          impact: low          
        register: change_request_main_out

      - name: Cache the Change Request number in memory | {{ ansible_date_time.iso8601 }}
        ansible.builtin.set_fact:
          change_task_number: "{{ change_request_main_out.record.number }}"
          cacheable: yes
        
      - debug:
          msg: Task Emergency Password Rotation "{{ change_task_number }}" is now being closed | Approval {{ ansible_date_time.iso8601 }}  

      - name: Close the CR {{ change_task_number }} after a successful execution on {{ ansible_date_time.iso8601 }}
        servicenow.itsm.change_request:
          instance:
            host: "{{ sn_instance}}"
            username: "{{ sn_username }}"
            password:  "{{ sn_password }}"
          state: closed
          close_code: successful
          close_notes: successful
          assignment_group: Database
          number: "{{ change_task_number }}"

Log:

[ansible_admin@lnx000 ansible]$ time ansible-playbook ./playbooks/itsm_databases_password_change05.yml -kK
SSH password: 
BECOME password[defaults to SSH password]: 

PLAY [Omni-Vendor Omni-Environment Emergency Password Rotation Process ID 2972.56] ***********************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Create main change request on 2025-10-22T00:36:00Z] ************************************************************************************************************************************************************************************************************
[WARNING]: Encountered unknown value Other while mapping field category.
changed: [localhost]

TASK [Cache the Change Request number in memory | 2025-10-22T00:36:00Z] **********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [debug] *********************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => 
  msg: Task Emergency Password Rotation "CHG0030100" is now being closed | Approval 2025-10-22T00:36:00Z

TASK [Close the CR CHG0030100 after a successful execution on 2025-10-22T00:36:00Z] **********************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => changed=false 
  msg: 'Unexpected response - 403 b''{"error":{"message":"Operation Failed","detail":"Operation against file \''change_request\'' was aborted by Business Rule \''Change Model: Check State Transition^b71e12a083f0b210f28198c6feaad3e3\''. Business Rule Stack:Change Model: Check State Transition"},"status":"failure"}'''

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=4    changed=1    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   


real    0m11.882s
user    0m1.435s
sys     0m0.432s
[ansible_admin@lnx000 ansible]$ 

 

3 REPLIES 3

Kieran Anson
Kilo Patron

Hey,

Change requests have a defined life cycle and need to transition through each stage in order to be closed.

 

For your demo purposes, I'd suggest the following:

 

  • Check whether the 'Change Registration' model is available by using the application navigator and seeing whether Change Registration appears as a record. If it is, update it so 'available in create new' is true

KieranAnson_0-1761147182883.png

  • Rather than using type: standard and state: new, use chg_model: 7840d2515323101034d1ddeeff7b12a6. I'm assuming this Ansible action supports change models.
  • The change will be created in a state of review
  • You can then update the change by setting the state to state: closed

Thank you,  @Kieran Anson . Your solution would have worked if the Ansible ServiceNow ITSM collection supported the "chg_model" parameter. Unfortunately, it does not, not yet at least. It may be available in one of the read-only modules, like change_request_info. But not in the create/edit/delete modules.

But I followed your solution in another way. I simply added additional steps inside the automation. They are create=>schedule=>implement=>review=>close. Each step uses the cached CR number , they just pass it along to execute the changes.

It works now. Thank you again.

clerambeau3
Kilo Contributor

I answered my own question, but my solution was removed as spam. Why?

clerambeau3_0-1761147322498.png