- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 11:53 PM - edited 11-23-2023 01:22 AM
Hi All,
I have created a catalog item in my PDI1 which is used to update system properties on PDI2.
Once request is submitted, then a workflow triggers and a Run Script runs inside the workflow to invoke Rest message to send the request to PDI2 but it is not working. I get all the debug logs on PDI1 but I do not get any logs in PDI2. Please suggest me what could be the reason.
Run Script:
var reqUser = current.variables.requester;
var targetIns = current.variables.target_instance;
var mrvs_data = current.variables.integration_details;
//gs.info("MRVS DATA "+ mrvs_data);
var obj = {};
obj.requester = reqUser;
obj.target_instance = targetIns;
obj.details = [];
for(var i=0;i<mrvs_data.length;i++) {
obj.details.push(mrvs_data[i]);
}
updateApiDetails(obj);
function updateApiDetails(object){
targetIns = targetIns.replaceAll(" ", "").toLowerCase();
if (targetIns == "dev")
targetIns = "devinstance";
else if (targetIns == "test")
targetIns = "testinstance";
else if (targetIns == "prod")
targetIns = "prodinstance";
else if (targetIns == 'partner')
targetIns = "dev94xxxx";
var endPoint = 'https://' + targetIns + '.service-now.com/api/383xxx/auto_update_api/test';
var request = new sn_ws.RESTMessageV2();
request.setEndpoint();
request.setHttpMethod('put');
//userName and pwd to access the target instance
var user = '*******';
var password = '********';
request.setBasicAuth(user, password);
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader('Content-Type','application/json');
request.setRequestBody(object);
//gs.info("IAMIN in request "+request );
var response = request.execute();
//gs.info("IAMIN in response "+response );
var statusCode = response.getStatusCode();
gs.info("Status code "+statusCode);
}
#### Scripted API in target instance to update properties ###
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 08:51 PM
HI @kumaraj ,
I trust you are doing great.
It seems you're encountering an issue where the Run Script in your ServiceNow workflow is not successfully sending logs or making updates in PDI2. Based on your script and description, here are a few suggestions and areas to check:
-
Endpoint URL in Run Script: Ensure that the endpoint URL you're constructing (
var endPoint = 'https://' + targetIns + '.service-now.com/api/383xxx/auto_update_api/test';
) is correct. The domain should correctly point to PDI2, and the API path should be valid. Double-check for any typos or incorrect instance names. -
Authentication Credentials: Verify that the user credentials used in the script (
var user = '*******'; var password = '********';
) have the necessary permissions on PDI2 to execute the required operations. It’s also important to ensure these credentials are kept secure. -
HTTP Method and Content-Type: You're using
request.setHttpMethod('put');
and'Content-Type','application/json'
. Confirm that the API on PDI2 is configured to accept PUT requests and JSON content. Sometimes, APIs expect POST requests instead. -
Request Body Formatting: Make sure the
object
you're sending inrequest.setRequestBody(object);
is correctly formatted as a JSON string. You might need to useJSON.stringify(object)
to convert it to a JSON string. -
Error Handling: It appears that there is no error handling in the script after executing the REST call. It's important to add error handling to capture any exceptions or error responses from the API call. This can provide more insight into why the request might be failing.
-
Checking Logs in PDI2: Since you're not seeing logs in PDI2, verify that the Scripted REST API on PDI2 is being hit. Check if there are any access logs or errors logged in PDI2 that can provide clues.
-
Scripted REST API in PDI2: Review the Scripted REST API on PDI2 to ensure it is set up correctly to handle incoming requests and to log information as expected.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 01:38 PM
Hi, what do your logs show you? Was the payload sent successfully? Was it acknowledged by the target instance? What was the response code?
Have you confirmed that the target is configured correctly, can you update the target record using the same account credentials and a tool like Postman?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 08:51 PM
HI @kumaraj ,
I trust you are doing great.
It seems you're encountering an issue where the Run Script in your ServiceNow workflow is not successfully sending logs or making updates in PDI2. Based on your script and description, here are a few suggestions and areas to check:
-
Endpoint URL in Run Script: Ensure that the endpoint URL you're constructing (
var endPoint = 'https://' + targetIns + '.service-now.com/api/383xxx/auto_update_api/test';
) is correct. The domain should correctly point to PDI2, and the API path should be valid. Double-check for any typos or incorrect instance names. -
Authentication Credentials: Verify that the user credentials used in the script (
var user = '*******'; var password = '********';
) have the necessary permissions on PDI2 to execute the required operations. It’s also important to ensure these credentials are kept secure. -
HTTP Method and Content-Type: You're using
request.setHttpMethod('put');
and'Content-Type','application/json'
. Confirm that the API on PDI2 is configured to accept PUT requests and JSON content. Sometimes, APIs expect POST requests instead. -
Request Body Formatting: Make sure the
object
you're sending inrequest.setRequestBody(object);
is correctly formatted as a JSON string. You might need to useJSON.stringify(object)
to convert it to a JSON string. -
Error Handling: It appears that there is no error handling in the script after executing the REST call. It's important to add error handling to capture any exceptions or error responses from the API call. This can provide more insight into why the request might be failing.
-
Checking Logs in PDI2: Since you're not seeing logs in PDI2, verify that the Scripted REST API on PDI2 is being hit. Check if there are any access logs or errors logged in PDI2 that can provide clues.
-
Scripted REST API in PDI2: Review the Scripted REST API on PDI2 to ensure it is set up correctly to handle incoming requests and to log information as expected.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 02:55 AM
Thank you Amit for the detailed troubleshooting step. Now I think I can handle it. Thanks.