Skip to content

Instantly share code, notes, and snippets.

@njames
Created August 14, 2019 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save njames/fbe20e73376768a215e05451c946359a to your computer and use it in GitHub Desktop.
Save njames/fbe20e73376768a215e05451c946359a to your computer and use it in GitHub Desktop.
example code for integrating into service now from fiori
method get_assignment_group.
data: uri type string
, group type ref to data
, group_row type ref to data
, group_name type string
, response type ref to if_rest_entity
.
* read the group name from config * hard coded from now
group_name = |(UXC) End User Compute|.
* * create a http client
me->create_client( ).
uri = |/sys_user_group?sysparm_limit=1&name={ group_name }|.
* Set the URI if any
cl_http_utility=>set_request_uri(
exporting
request = me->http_client->request " HTTP Framework (iHTTP) HTTP Request
uri = uri " URI String (in the Form of /path?query-string)
).
* Set request header if any
call method me->rest_client->if_rest_client~set_request_header
exporting
iv_name = 'accept'
iv_value = 'application/json'.
call method me->rest_client->if_rest_client~set_request_header
exporting
iv_name = 'content-type'
iv_value = 'application/json'.
* HTTP GET
me->rest_client->if_rest_client~get( ).
response = me->rest_client->if_rest_client~get_response_entity( ).
data(http_status) = response->get_header_field( '~status_code' ).
data(json_response) = response->get_string_data( ).
group = /ui2/cl_json=>generate( json = json_response ).
field-symbols: <data> type data
, <result> type data
, <field> type any
.
data(ref) = /ui2/cl_data_access=>create( iv_data = group iv_component = `RESULT[1]`)->ref( ) .
if ref is bound.
assign ref->* to <data>.
assign component `SYS_ID` of structure <data> to <result>.
endif.
* get REFERENCE OF <result> into <field>.
ASSIGN <result>->* to <field>.
if <field> is assigned.
r_group_id = <field>.
endif.
endmethod.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment