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.”

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);
}
});
}

 

 

Bhuvan
Giga 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