Unable to Glide the sys id of current incident record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 06:26 AM
As per the below script we want to glide the current incident in query to perform certain action on it.
Howvever we have tried the querey gr.addQuery('sys_id', current.sys_id) and tried "('sys_id', ccurrent.getUniqueValue())
But it did not work.
Please suggest.
getCIList2: function() {
// gs.log('running test ');
var myDateTime = new GlideDateTime();
myDateTime.setValue('2023-08-01 00:00:00');
var user_id = this.getParameter('sysparm_role');
gs.log('running test 2');
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', current.getUniqueValue());
gs.log('running inc '+ current.getUniqueValue());
gr.query();
if(gr.next()){
gs.log('running gr.next() ');
var createdDateTime = new GlideDateTime(gr.sys_created_on);
gs.log('running '+ createdDateTime);
if(createdDateTime.before(myDateTime))
return 'false';
else {
var ci = new GlideRecord('cmdb_ci_pc_hardware');
ci.addQuery('assigned_to', user_id);
gs.log('running user '+ user_id);
ci.query();
if(ci.next()){
if (ci.getRowCount() == 1) {
//gs.log('JT: Row count is ' + ci.getRowCount());
return ci.getValue('sys_id');
}
return "List";
}
return "";
}
}
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 06:42 AM
This is a Script Include, correct?
If so, there is no access to "current" from a SI, you'll need to either pass the incident sys_id into the SI as a parameter from whichever record you're calling it from. Like you're doing here with the user_id:
var user_id = this.getParameter('sysparm_role');
Or, you're going to need to do a gliderecord query against the Incident table and look up the sys_id.
Thanks,
Joe S.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 08:02 AM
Please answer few question
1) how and from where are you calling this script include
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 09:22 AM
We are calling this script include from client script below is the script.
function onChange(control, oldValue, newValue, isLoading) {
//if (isLoading) {
// return;
//}
var created = g_form.getValue('sys_created_on');
if(created ) {
}
if (newValue == '') {
g_form.setVisible('cmdb_ci', true);
g_form.clearValue('cmdb_ci');
return;
}
var caller = g_form.getValue('caller_id');
var ga = new GlideAjax('Inc_ci');
ga.addParam('sysparm_name', "getCIList");
ga.addParam('sysparm_role', caller);
ga.getXMLAnswer(function(answer) {
//g_form.addInfoMessage('Answer '+answer);
if (answer != '' && answer != 'List') { // Ci available - only 1
g_form.setDisplay('cmdb_ci', true);
g_form.setValue('cmdb_ci', answer);
} else if (answer == 'List') { // Ci available - multiple
g_form.clearValue('cmdb_ci');
g_form.setVisible('cmdb_ci', true);
} else if (answer == '') { // Ci avaialble - No
g_form.clearValue('cmdb_ci');
}
});
}
//Type appropriate comment here, and begin script below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2023 09:42 PM
you are sending caller_id but you are querying with incident sysId
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader