- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 04:44 AM
Hi there,
I have a Service Portal Catalog item which contains a variable that is a reference to "cmdb_ci_computer".
When users fill in this field (variable), they have to fill in a value that is available as name (field "name") within "cmdb_ci_computer".
However, within "cmdb_ci_computer", we have created an additional field. It's called "u_stickernumber". Now I want users in the above mentioned case, to fill in the stickernumber instead of the name, to find/select the right record within "cmdb_ci_computer".
I attempt to achieve this, I gave my variable reference, the following "variable attribute":
"ref_auto_completer=AJAXTableCompleter, ref_ac_columns=u_stickernumber"
Unfortunately, this does not work. Anyone any idea how to do this?
Thanks and kind regards,
Adam
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 05:19 AM
that's correct, at least they can search with it
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 07:38 AM
Please close the thread by marking my response as correct so that it helps future members.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 07:53 AM - edited ‎02-18-2025 08:02 AM
Thanks @Ankur Bawiskar !
The "variable attribute" for variable "assetnumber" is now; ref_auto_completer=AJAXTableCompleter, ref_ac_columns=u_stickernumber, ref_ac_columns_search=true
Now I want to show the stickernumber within my Catalog Item form variable "assetnumber" while;
- Filling in Catalog Item form (OnLoad) - Frontend / Service Portal
- Editting Catalog Item form (OnChange) - Frontend / Service Portal
- While opening Requested and/or Service Catalog Task's - Backend
I've made:
- OnLoad Client Script
- OnChange Client Script
- Script Include
But unfortunately it still does not work. Any idea about the cause? Thanks!
OnLoad Client script:
function onLoad() {
var fieldName = 'assetnumber';
var gFormValue = g_form.getValue(fieldName);
if (gFormValue) {
updateStickerNumber(fieldName, gFormValue);
}
}
function updateStickerNumber(field, sys_id) {
var ga = new GlideAjax('GetStickerNumber');
ga.addParam('sysparm_name', 'getStickerNumber');
ga.addParam('sysparm_sys_id', sys_id);
ga.getXMLAnswer(function(response) {
if (response) {
g_form.setDisplayValue(field, response);
}
});
}
OnChange Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
updateStickerNumber('assetnumber', newValue); // Roep dezelfde functie aan als in onLoad
}
Script Include:
var GetStickerNumber = Class.create();
GetStickerNumber.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getStickerNumber: function() {
var sys_id = this.getParameter('sysparm_sys_id');
var gr = new GlideRecord('cmdb_ci_computer');
if (gr.get(sys_id)) {
return gr.u_stickernumber;
}
return 'Sticker not found';
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 07:56 AM
I believe I have answered your original question.
Please close the thread by marking my response as correct and the discussion can continue further.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-18-2025 07:58 AM
no scripting required. You can use auto populate feature i.e. make the string variable dependent on assetnumber
Auto-populate a variable based on a reference type variable (Utah)
Also it makes no sense to use this for on-load as when form loads you are not populating any default value in Computer variable
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader