Lab 7.2 Web Service Consumer- Issue with retrieving a record from a table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-28-2023 10:08 AM - edited ‎11-01-2023 11:12 AM
Hello, I am currently working on the Application Developer Fundamentals course lab. The lab calls to treat my dev instance as a web service consumer and my test instance as the publisher/provider. The goal of this part of the lab is to use the rest api to retrieve a password from my test instance based on the sent asset tag of a loaner laptop whos state has been updated/inserted to Ready for Pickup. For some reason communication between the two instances does not seem to be working. I imported an excel file into my test instance which was correctly loaded into my target table 'Password Vault'. I am using a business rule with the REST script to log the password of the asset tag for the laptop in the developer application log. I modified the script exactly how it followed in the video walk-through yet for some reason it does not show up in my application log. I know the rest script is not the problem because the preview message body in my test instance originally logs the password how I would like it to in the dev instance application log. I followed every step from the walk-through video but am still having an issue. The script I am using to do this is included below. The first image is the list of messages from the application log. The second image is how i would like it to be logged in the application log. I am fairly new to ServiceNow and this is my introduction to web services so if there is more information needed on my end please ask!
(function executeRule(current, previous /*null when async*/ ) {
if(current.item == "cmdb_ci_computer"){
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://nowlearning-nlinst01184219-test-0001.lab.service-now.com/api/now/table/x_cdltd_loaner_req_password_vault?sysparm_query=u_asset%3D'+current.cmdb_ci.asset_tag+'&sysparm_fields=u_password&sysparm_limit=1');
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = '*********';/*password is correct*/
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
var response = request.execute();
gs.info(response.getBody());
var obj = JSON.parse(response.getBody());
var myPass = obj.result[0].u_password;
gs.info('u_password: ' + myPass);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2023 12:26 PM
Hi, unfortunately your post does not make your configuration or issue clear.
You make mention of multiple points in your structure\process (data import\transform, REST and email notification); but no clear details of the behavior that is unexpected (or correct), and unfortunately without clear context partial screen-shots do not help much in evaluation of your issue.
Is your data loaded/transformed correctly into your destination table?
What does the REST Get do within your operational context\context of your issue?
You appear to indicate that the issue is with the content of your email notification, but do not appear to have provided details of your notification email script?
Perhaps you could update this thread with clear details of your configuration, diagnostics and relevant code in plain text, so that the community are in a better position to review and assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2023 11:16 AM
Hey Tony, thank you for the the reply. Hopefully the edited post above allows you or someone else to better assist me. I only have a bit of experience with ServiceNow, and this is my introduction to web services. If you need more information from me, please feel free to ask!