Regarding to display CI name and serial numebr in same field

Avinash_M
Tera Contributor

Hello Team,
I have a requirement in service catalog, The CI name and serial number of same CI should be visible in CI field.
Example: CI - Serial number (abc1234 - 009988776).
Is it possible? I have written script include client callable over reference field type but its not working,getting serial number in log but its not setting up over CI Name field, is there anyways?

1 ACCEPTED SOLUTION

Hi @Avinash_M 

Yes, that is expected. In a variable, only one value will display, and that’s based on the display value. You can search using two values, but the display will always be based on one value.”

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

View solution in original post

6 REPLIES 6

Ajay_Chavan
Kilo Sage

Try below it should work, Solution : Script Include + Client Script

Script Include (Name: GetCIDisplay, Client callable: true):

var GetCIDisplay = Class.create();
GetCIDisplay.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCIDisplay: function() {
var ciSysId = this.getParameter('ci_sys_id');
var ci = new GlideRecord('cmdb_ci');
if (ci.get(ciSysId)) {
var displayValue = ci.name.toString();
if (ci.serial_number && ci.serial_number != '') {
displayValue += ' - ' + ci.serial_number.toString();
}
return displayValue;
}
return '';
},
type: 'GetCIDisplay'
});

Client Script (Type: onChange, Variable: your CI field):

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) return;

var ga = new GlideAjax('GetCIDisplay');
ga.addParam('sysparm_name', 'getCIDisplay');
ga.addParam('ci_sys_id', newValue);
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('your_ci_field_name', newValue, answer);
}
});
}

 

 

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****

Bhuvan
Kilo Patron

@Avinash_M 

 

Can you share your script to see why it is not working ?

 

You can glide record on cmdb_ci table using CI sys_id and get the details of Serial number [if field value is not null] and CI name and concatenate it and set the value in the variable.

 

If this helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan