Pushing update sets using API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 04:07 AM
We need to fetch the XML from a location and then preview and commit using API, has anyone done this?
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 05:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 11:53 PM
Yes, you can fetch XML from a location and then preview and commit using ServiceNow's REST API. Here are the steps:
1. Fetch XML from a location:
- Use the REST API to fetch the XML from a location. You can use the GET method to fetch the XML.
- For example, you can use the following code to fetch the XML:
javascript
var restMessage = new sn_ws.RESTMessageV2();
restMessage.setHttpMethod('get');
restMessage.setEndpoint('your_endpoint_url');
var response = restMessage.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
2. Preview the XML:
- After fetching the XML, you can preview it. You can use the gs.info() method to log the XML for preview.
- For example, you can use the following code to preview the XML: javascript gs.info(responseBody);
3. Commit the XML:
- After previewing the XML, you can commit it to a table in ServiceNow.
- You can use the parseXML() method to parse the XML and then use the insert() method to commit the data to a table.
- For example, you can use the following code to commit the XML:
javascript
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(responseBody);
var gr = new GlideRecord('your_table_name');
gr.initialize();
gr.column1 = xmlDoc.getNodeText('//node1');
gr.column2 = xmlDoc.getNodeText('//node2');
gr.insert(); - Replace 'your_table_name', 'column1', 'column2', '//node1', and '//node2' with your actual table name, column names, and XML node paths.
Please note that you need to have the appropriate roles and permissions to use the REST API and to commit data to a table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 12:22 PM
This answer as well as the next one clearly looks like someone has just asked ChatGPT and pasted the response here without checking if it makes sense or not. ( I can tell from the "javascript" keywords before the code which ChatGPT uses.)
Unfortunately ChatGPT is "hallucinating" often when it comes to ServiceNow: It believes it's answers sound "fitting" but doesn't really *understand* how SN works.
In this case
* the Requester probably wanted to upload the files from a local location and not some http-url.
* a preview for an update set is not equal to just using gs.info to "look" at it.
* committing is not "committing it to a table" like in an ordinary Database.
@sourav1999: Please do not just post ChatGPT responses here: The Original requestor could have easily done this himself and he would have known to take the answer with caution.
At a minimum, please clearly mark your response as "Source: ChatGPT" !
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2024 02:31 PM
there is OOB functionality for working with update sets, how they are promoted to other instances.
