- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2021 05:39 AM
Requirement: need to auto populate the 'configuration item' variable based on 'caller_id' variable.
What are the 'CI's' related to him and need to populate only if caller is VIP.
I know it can be done by writing a script include and onchnage client script. but I'm a admin need some assistance with script.
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2021 06:28 AM
Hi,
To get CIs owned by caller then use below scripts. If you want to get CIs assigned to caller then change the query.
Script Include :
var userOwnCI= Class.create();
userOwnCI.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getComputer: function(){
var caller= this.getParameter('sysparm_caller');
//query to computer table and get the list of computers owned by caller
var gr= new GlideRecord('cmdb_ci_computer'); //change table name as the requirements
gr.addQuery('owned_by',caller); //owned CI.
//For assigned assets change above line to gr.addQuery('assigned_to',caller);
gr.query();
if(gr.next())
{
return gr.getUniqueValue();
}
},
type: 'userOwnCI'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//check VIP user
var vipUser='false';
var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function
function doAlert(caller) { //reference is passed into callback as first arguments
if (caller.vip == 'true')
vipUser= 'true';
if (newValue && vipUser =='true') { //if VIP user
var ga= new GlideAjax('userOwnCI');
ga.addParam('sysparm_name','getComputer');
ga.addParam('sysparm_caller', newValue);
ga.getXML(getComputerDet);
}
}
}
function getComputerDet(response)
{
var answer = response.responseXML.documentElement.getAttribute('answer');
//Sets the field value
g_form.setValue('cmdb_ci',answer);
}
If I have answered your question, please mark my response as correct and/or helpful.
Thanks,
Suseela P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2021 06:28 AM
Hi,
To get CIs owned by caller then use below scripts. If you want to get CIs assigned to caller then change the query.
Script Include :
var userOwnCI= Class.create();
userOwnCI.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getComputer: function(){
var caller= this.getParameter('sysparm_caller');
//query to computer table and get the list of computers owned by caller
var gr= new GlideRecord('cmdb_ci_computer'); //change table name as the requirements
gr.addQuery('owned_by',caller); //owned CI.
//For assigned assets change above line to gr.addQuery('assigned_to',caller);
gr.query();
if(gr.next())
{
return gr.getUniqueValue();
}
},
type: 'userOwnCI'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//check VIP user
var vipUser='false';
var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function
function doAlert(caller) { //reference is passed into callback as first arguments
if (caller.vip == 'true')
vipUser= 'true';
if (newValue && vipUser =='true') { //if VIP user
var ga= new GlideAjax('userOwnCI');
ga.addParam('sysparm_name','getComputer');
ga.addParam('sysparm_caller', newValue);
ga.getXML(getComputerDet);
}
}
}
function getComputerDet(response)
{
var answer = response.responseXML.documentElement.getAttribute('answer');
//Sets the field value
g_form.setValue('cmdb_ci',answer);
}
If I have answered your question, please mark my response as correct and/or helpful.
Thanks,
Suseela P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-22-2021 07:38 AM
Thank you so much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-13-2022 08:47 AM
Hi! I need to do this for every user, not VIPs, and based on Assigned to instead of owner. What needs to change in the Client Script version?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2022 12:49 PM
What would be the script for any user, not just VIP? New to Servicenow and scripts. Thanks!