[Python] Pysnow module (Python for Servicenow) - how to create requested items?

Discussão em 'Python' iniciado por Stack, Março 25, 2025.

  1. Stack

    Stack Membro Participativo

    I recently start using pysnow-module for automating my work at Servicedesk. My problem is that i don't know how to create Requested Items.

    I have managed to create new incidents and new requests, also update them. I have also succeeded in modifying Requested Items, but i'm stuck at not knowing how to turn Requests into Requested Items.

    I've tried following pieces of code, all starting with this

    s = pysnow.Client(instance='Secret domain', user='Secret-user', password='Secret')


    Then continuing with following tries:

    def new_ritm():
    result = s.insert(table='sc_req_item', payload={'field1': 'value1',
    'field2': 'value2'})
    print(result['number'])
    luo_uusi_ritm()

    File "XXXXXXXXXXXXXXXXXX", line 51, in <module>luo_uusi_ritm()
    File"XXXXXXXXXXXXXXXXXX", line 47, in new_ritmresult = s.insert(table='sc_req_item', payload={'field1': 'value1', 'field2': 'value2'})
    File "XXXXXXXXXXXXXXXXXX", line 90, in insert return r.insert(payload)
    File "XXXXXXXXXXXXXXXXXX", line 108, in insert return self._get_content(response)
    File "XXXXXXXXXXXXXXXXXX", line 290, in _get_contentreturn content_json['result']
    KeyError: 'result'


    Also tried modifying REQ, insert new values:

    result = s.insert(table='sc_req_item', payload={'sc_req_item.request':
    'REQ0994143'})


    But get an error:

    "File "xxxxxxxxxxxxx, line 290, in _get_content
    return content_json['result']
    KeyError: 'result'


    EDIT: Suggestion 1: I couldn't add the


    "request_params={'sysparm_display_value': 'true'})" , because it gives me an "Unexpected argument" error
    ​

    I entered the following code:

    s = pysnow.Client(instance=XXXX,user=XXXXX,password=XXXXXX)


    try:
    result = s.insert(table='sc_req_item', payload={'field1': 'value1',
    'field2': 'value2'})
    except pysnow.UnexpectedResponse as e:
    print("%s, details: %s" % (e.error_summary, e.error_details))


    Which gives me an error:


    Traceback (most recent call last):

    File "XXXXXXXXXXXX", line 63, in stack_experiment()

    File "XXXXXXXXX", line 59, in stack_experiment result = s.insert(table='sc_req_item', payload={'field1': 'value1','field2': 'value2'})

    File "XXXXXXXXXXXXX", line 90, in insert return r.insert(payload)

    File "XXXXXXXXXXXXX", line 108, in insert return self._get_content(response)

    File "XXXXXXXXXXX", line 290, in _get_content return content_json['result']

    KeyError: 'result'
    ​

    Suggestion 2:


    Maybe you are confused using Client.insert instead of Request.insert
    ​

    I am confused about it. Should i change the starting code "s = pysnow.Client(etc."?

    I went to read the docs one more time and i've understood for new requests, i should use pysnow.Request, so i tried once more with:

    r = pysnow.Request(instance='Secret domain', user='Secret-user',
    password='Secret', method='POST', table='sc_req_item')

    try:

    result = r.insert(payload={'field1': 'value1', 'field2': 'value2'})

    except pysnow.UnexpectedResponse as e:

    print("%s, details: %s" % (e.error_summary, e.error_details))


    And i got an error:

    Traceback (most recent call last):
    File "xxxx", line
    7, in <module>
    r = pysnow.Request(instance='xxxx', user='xxxx',
    password='xxxxx', method='POST', table='sc_req_item')
    File "xxxxx", line 29, in __init__
    self.default_payload = kwargs.pop('default_payload')
    KeyError: 'default_payload'

    Continue reading...

Compartilhe esta Página