- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2023 01:32 PM - edited ‎05-01-2023 01:36 PM
I am having trouble with the IRE API (specifically createOrUpdateCi https://docs.servicenow.com/bundle/utah-api-reference/page/app-store/dev_portal/API_reference/Identi...) in a scoped app.
Since this is in a scoped app, I am using the sn_cmdb namespace. Unfortunately, that's as far as I get. When I send JSON through, line 13 returns, "ConversionError: The undefined value has no properties."
My script looks like this:
var LogicMonitorCmdbRestUtils = Class.create();
LogicMonitorCmdbRestUtils.prototype = {
initialize: function () {
},
postResource: function (resourceJson) {
var answer = {};
try {
input = JSON.stringify(resourceJson);
gs.info("The value of input is: {0}", input);
var output = JSON.parse(sn_cmdb.IdentificationEngineScriptableApi.createOrUpdateCI('LogicMonitor CMDB REST API', input));
gs.info("The IRE API returned: {0}", JSON.stringify(output));
answer.http_status = "200";
answer.status_message = "The script ran successfully.";
} catch (exception) {
answer.http_status = "500";
answer.status_message = 'Internal ServiceNow error: ' + exception + '. If it is populated, the value of output is: ' + output;
gs.error(JSON.stringify(answer));
return answer;
}
return answer;
},
type: 'LogicMonitorCmdbRestUtils'
};
Running the same script, but from the global scope, in a different instance (with snc instead of sn_cmdb being the only difference) works great. Any idea what I need to do here?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2023 07:38 AM
This code is working:
var LogicMonitorCmdbRestUtils = Class.create();
LogicMonitorCmdbRestUtils.prototype = {
initialize: function () {
},
postResource: function (payload) {
var answer = {};
try {
input = JSON.stringify(payload);
gs.info("The value of input is: {0}", input);
var output = sn_cmdb.IdentificationEngine.createOrUpdateCI('LogicMonitor CMDB REST API', input);
gs.info("The IRE API returned: {0}", JSON.stringify(output));
answer.http_status = "200";
answer.status_message = "The script ran successfully.";
} catch (exception) {
answer.http_status = "500";
answer.status_message = 'Internal ServiceNow error: ' + exception + '. If it is populated, the value of output is: ' + output;
gs.error(JSON.stringify(answer));
return answer;
}
return answer;
},
type: 'LogicMonitorCmdbRestUtils'
};
I changed a variable name ("resourceJson" to "payload") and took the
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2023 03:02 PM
Are you getting the value you expected for input on line 10, in both cases?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-01-2023 06:17 PM
Yeah, according to the log, the JSON looks like this for the scoped app:
[
{
"items": [
{
"className": "cmdb_ci_win_server",
"values": {
"company": "cf10fc90dbbb5c101a4fba03e29619f1",
"name": "test",
"x_crit2_logicmonit_logicmonitor_id": "1490"
},
"sys_object_source_info": {
"source_name": "My custom source",
"source_recency_timestamp": "5/1/2023 10:35:17 AM"
}
}
]
}
]
And like this for the global app:
[
{
"items": [
{
"className": "cmdb_ci_win_server",
"values": {
"name": "test",
"u_logicmonitor_id": "1490"
},
"sys_object_source_info": {
"source_name": "My custom source",
"source_recency_timestamp": "5/1/2023 10:35:17 AM"
}
}
]
}
]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-02-2023 07:38 AM
This code is working:
var LogicMonitorCmdbRestUtils = Class.create();
LogicMonitorCmdbRestUtils.prototype = {
initialize: function () {
},
postResource: function (payload) {
var answer = {};
try {
input = JSON.stringify(payload);
gs.info("The value of input is: {0}", input);
var output = sn_cmdb.IdentificationEngine.createOrUpdateCI('LogicMonitor CMDB REST API', input);
gs.info("The IRE API returned: {0}", JSON.stringify(output));
answer.http_status = "200";
answer.status_message = "The script ran successfully.";
} catch (exception) {
answer.http_status = "500";
answer.status_message = 'Internal ServiceNow error: ' + exception + '. If it is populated, the value of output is: ' + output;
gs.error(JSON.stringify(answer));
return answer;
}
return answer;
},
type: 'LogicMonitorCmdbRestUtils'
};
I changed a variable name ("resourceJson" to "payload") and took the