Ilmari Kumpula
Ilmari Kumpula

Reputation: 1483

Pysnow - How to do an update record by based on something other than by only text-value?

I have the following problem.

I've written a program on Python to be run on a web-page which enters records into ServiceNow. I work in a help desk and for example automating password resets would be a huge help. I can create these records through Pysnow-module for Python and everything else works fine, but I can only enter values (like Configuration Item) only based on their text-name. This is a problem because many values have different companies, billing etc. and they have the same name, so my queries end up for random companies. User could be from company A, timecard for company X, item for company E and so on.

When i fetch a record with a certain field:

Command: r.get_one(fields=['u_configuration_item'])

I get this as response:

{'link': 'https://xxxxx.service
now.com/api/now/table/core_company/f7a9a64430b070c8e017981c4ba7a0e7',
'value': 'f7a9a64430b070c8e017981c4ba7a0e7'}

When i try for example make a dictionary out of the response:

dict = {'value': 'xxx', 'link': 'xxx'}
'u_configuration_item': dict

It doesn't give me an error, but just makes a record with blank field.


The following kind of code works fine, but it's just this 'Random Value' comes with a company/billing which is not right for the customer.

s = pysnow.Client(instance='xxxx', user='xxxx',password='xxxx')
result = r.update({'u_configuration_item': 'Random Value'})
print(result['number'])

I've tried googling, entering different kinds of info, but just can't get forward.

Upvotes: 0

Views: 825

Answers (1)

Ilmari Kumpula
Ilmari Kumpula

Reputation: 1483

I found an answer, i though i had tried this before, but just by replacing "Random value" with sys_id which is unique to every single record it works. I'm happy i was persistent though and keep trying, almost was about to give up.

Upvotes: 0

Related Questions