- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:05 AM
Hi Team,
I have a string field on incident and I have a requirement to set this field value from the soap Api body response.
here the code written in async business rule.Howcan i do this.
Thanks,
Ankit
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:11 AM
Here are the steps to set a string field value from a SOAP API response using an asynchronous business rule in ServiceNow:
1. Create an asynchronous business rule:
- Navigate to System Definition > Business Rules.
- Click on New to create a new business rule.
- Set the 'When to run' section as 'After' and 'Async' to make it an asynchronous business rule.
2. In the 'Advanced' tab, write a script to call the SOAP API:
- Use the 'SOAPMessageV2' function to create a new SOAP message.
- Set the endpoint, SOAP action, and any necessary headers.
- Use the 'setRequestBody' method to set the body of the SOAP message.
- Use the 'getXMLResponse' method to get the response from the SOAP API.
3. Parse the SOAP response:
- Use the 'XMLDocument2' function to parse the SOAP response.
- Use the 'getNode' method to get the specific node from the SOAP response that contains the value you want to set in the string field.
4. Set the string field value:
- Use the 'setValue' method to set the value of the string field on the incident record with the value from the SOAP response.
Here is a sample code:
javascript
(function executeRule(current, previous /*null when async*/) {
// Create a new SOAP message
var sm = new SOAPMessageV2('your_soap_message', 'your_soap_function');
// Set the endpoint, SOAP action, and any necessary headers
sm.setEndpoint('your_endpoint_url');
sm.setSOAPAction('your_soap_action');
// Send the SOAP message and get the response
var response = sm.getXMLResponse();
// Parse the SOAP response
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(response.toString());
// Get the value from the SOAP response
var value = xmlDoc.getNode('your_node').getTextContent();
// Set the value of the string field on the incident record
current.your_string_field = value;
// Update the incident record
current.update();
})(current, previous);
Please replace 'your_soap_message', 'your_soap_function', 'your_endpoint_url', 'your_soap_action', 'your_node', and 'your_string_field' with your actual SOAP message, function, endpoint URL, SOAP action, node, and string field respectively.
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Please visit : https://nowkb.com/home
Our Website :https://nowkb.com/home
Link - https://nowgpt.ai/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:11 AM
Here are the steps to set a string field value from a SOAP API response using an asynchronous business rule in ServiceNow:
1. Create an asynchronous business rule:
- Navigate to System Definition > Business Rules.
- Click on New to create a new business rule.
- Set the 'When to run' section as 'After' and 'Async' to make it an asynchronous business rule.
2. In the 'Advanced' tab, write a script to call the SOAP API:
- Use the 'SOAPMessageV2' function to create a new SOAP message.
- Set the endpoint, SOAP action, and any necessary headers.
- Use the 'setRequestBody' method to set the body of the SOAP message.
- Use the 'getXMLResponse' method to get the response from the SOAP API.
3. Parse the SOAP response:
- Use the 'XMLDocument2' function to parse the SOAP response.
- Use the 'getNode' method to get the specific node from the SOAP response that contains the value you want to set in the string field.
4. Set the string field value:
- Use the 'setValue' method to set the value of the string field on the incident record with the value from the SOAP response.
Here is a sample code:
javascript
(function executeRule(current, previous /*null when async*/) {
// Create a new SOAP message
var sm = new SOAPMessageV2('your_soap_message', 'your_soap_function');
// Set the endpoint, SOAP action, and any necessary headers
sm.setEndpoint('your_endpoint_url');
sm.setSOAPAction('your_soap_action');
// Send the SOAP message and get the response
var response = sm.getXMLResponse();
// Parse the SOAP response
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(response.toString());
// Get the value from the SOAP response
var value = xmlDoc.getNode('your_node').getTextContent();
// Set the value of the string field on the incident record
current.your_string_field = value;
// Update the incident record
current.update();
})(current, previous);
Please replace 'your_soap_message', 'your_soap_function', 'your_endpoint_url', 'your_soap_action', 'your_node', and 'your_string_field' with your actual SOAP message, function, endpoint URL, SOAP action, node, and string field respectively.
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Please visit : https://nowkb.com/home
Our Website :https://nowkb.com/home
Link - https://nowgpt.ai/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:21 AM
@sumanta pal Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:14 AM
Hi Ankit,
I believe the API body response is captured in worknotes or some other field. If so, can you share the response format and text you need from it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 04:25 AM - edited 01-24-2024 04:29 AM
@Ankit Kumar6 do you really understand the solution provided by @sumanta pal?
@sumanta pal it seems to be more of a copy-past from a dump you maitain at https://nowkb.com/home