Module: Legion::Extensions::ServiceNow::BusinessRule::Runners::BusinessRule
- Includes:
- Helpers::Lex, Helpers::Client
- Included in:
- Client
- Defined in:
- lib/legion/extensions/service_now/business_rule/runners/business_rule.rb
Instance Method Summary collapse
- #create_business_rule(name:, collection:, script:, when_to_run: 'before', action_insert: false, action_update: false, action_delete: false, active: true) ⇒ Object
- #delete_business_rule(sys_id:) ⇒ Object
- #get_business_rule(sys_id:) ⇒ Object
- #list_business_rules(sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil) ⇒ Object
- #update_business_rule(sys_id:, script: nil, active: nil, name: nil) ⇒ Object
Methods included from Helpers::Client
#connection, #fetch_oauth2_token, #handle_response
Instance Method Details
#create_business_rule(name:, collection:, script:, when_to_run: 'before', action_insert: false, action_update: false, action_delete: false, active: true) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/extensions/service_now/business_rule/runners/business_rule.rb', line 24 def create_business_rule(name:, collection:, script:, when_to_run: 'before', action_insert: false, action_update: false, action_delete: false, active: true, **) body = { name: name, collection: collection, script: script, when: when_to_run, action_insert: action_insert, action_update: action_update, action_delete: action_delete, active: active } resp = connection(**).post('/api/now/table/sys_script', body) { business_rule: resp.body['result'] } end |
#delete_business_rule(sys_id:) ⇒ Object
51 52 53 54 |
# File 'lib/legion/extensions/service_now/business_rule/runners/business_rule.rb', line 51 def delete_business_rule(sys_id:, **) resp = connection(**).delete("/api/now/table/sys_script/#{sys_id}") { deleted: resp.status == 204, sys_id: sys_id } end |
#get_business_rule(sys_id:) ⇒ Object
19 20 21 22 |
# File 'lib/legion/extensions/service_now/business_rule/runners/business_rule.rb', line 19 def get_business_rule(sys_id:, **) resp = connection(**).get("/api/now/table/sys_script/#{sys_id}") { business_rule: resp.body['result'] } end |
#list_business_rules(sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/legion/extensions/service_now/business_rule/runners/business_rule.rb', line 11 def list_business_rules(sysparm_limit: 100, sysparm_offset: 0, sysparm_query: nil, **) params = { sysparm_limit: sysparm_limit, sysparm_offset: sysparm_offset } params[:sysparm_query] = sysparm_query if sysparm_query resp = connection(**).get('/api/now/table/sys_script', params) { business_rules: resp.body['result'] } end |
#update_business_rule(sys_id:, script: nil, active: nil, name: nil) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/legion/extensions/service_now/business_rule/runners/business_rule.rb', line 41 def update_business_rule(sys_id:, script: nil, active: nil, name: nil, **) body = {} body[:script] = script if script body[:active] = active unless active.nil? body[:name] = name if name resp = connection(**).patch("/api/now/table/sys_script/#{sys_id}", body) { business_rule: resp.body['result'] } end |