serial number populating on the incident form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 06:42 AM - edited 06-05-2024 06:42 AM
i tried to do a before br on the incident form . i have a field called u_impacted_asset so when i entered the caller infomation it should automatically populate the impacted asset box . it is not working now
// Get the caller's username from the incident ticket
var caller = current.caller_id;
// Query the alm_asset table to find the asset assigned to the caller
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('assigned_to', caller);
assetGr.query();
if (assetGr.next()) {
// Populate the u_impacted_asset field with the found asset's serial number
current.u_impacted_asset = assetGr.serial_number;
}
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 09:09 AM
Hi @chercm
You can try the below code with client script and script include:
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var callervalue=g_form.getValue('caller_id');
var caller=new GlideAjax('GetManagerDetailsScript');
caller.addParam('sysparm_name','getserialnumber');
caller.addParam('sysparm_caller',callervalue);
caller.getXMLAnswer(callback);
function callback(response){
var answer=response;
answer=answer.split(',');
alert(answer); // In place change based upon your requirement
}
//Type appropriate comment here, and begin script below
}
Script Include:
var GetManagerDetailsScript = Class.create();
GetManagerDetailsScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getserialnumber: function() {
var assetvalue = [];
var callerdata = this.getParameter('sysparm_caller');
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('assigned_to', callerdata);
assetGr.query();
while (assetGr.next()) { //used while loop because one user is having more than one asset
if(assetGr.serial_number!=''){
assetvalue.push(assetGr.serial_number.toString());
}
}
return assetvalue.toString();
}
});
Thanks and Regards
Sai venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 03:37 PM
@SAI VENKATESH when i change the caller field , the serial number is not populating on the impacted asset box . i tried to save the ticket and still the same
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2024 05:24 PM - edited 06-06-2024 06:43 AM
Hi @chercm
I have tried the same code in my PDI and It is populating the serial number(for single line text field) .and could you please check again.
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 06:24 AM
not working . i am trying to populate impacted asset field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2024 06:43 AM - edited 06-06-2024 06:47 AM
Hi @chercm
As per my understanding in the script you are populating serial number value in the "u_impacted_asset" field but it is not posibble since "u_impacted_asset" is reference variable.
If you want serial number to populate you can populate in the single line text or string field ..
and below I have added the code for you which I have done by using client script and script inlcude:
client script : On change of field name : Caller
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var callervalue=g_form.getValue('caller_id');
var caller=new GlideAjax('GetManagerDetailsScript');
caller.addParam('sysparm_naame','getserialnumber');
caller.addParam('sysparm_caller',callervalue);
caller.getXMLAnswer(callback);
function callback(response){
var answer=response;
answer=answer.split(',');
g_form.setValue('short_description',answer);
}
//Type appropriate comment here, and begin script below
}
Script Include :
var GetManagerDetailsScript = Class.create();
GetManagerDetailsScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getserialnumber: function() {
var assetvalue = [];
var callerdata = this.getParameter('sysparm_caller');
var assetGr = new GlideRecord('alm_asset');
assetGr.addQuery('assigned_to', callerdata);
assetGr.query();
while (assetGr.next()) {
if(assetGr.serial_number!=''){
assetvalue.push(assetGr.serial_number.toString());
gs.info("the asset value is " + assetvalue);
}
}
return assetvalue.toString();
}
});
Thanks and Regards
Sai venkatesh