Populate the multiple serial number in a single field based on selection of multiple Assets details
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2023 05:52 AM - edited 09-26-2023 10:30 PM
I have two fields one field is Assets details which data type is list , refer to hardware table and another filed is serial number which data type is single text.
Suppose Some of the user has multiple assets , so we want to populate the serial number respectively on selection of assets details in a single filed (like comma separated).
Solution :-
1. OnChangeCatalog client script :-
2. Script Include :-
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor,{
},
- 1,038 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 03:09 AM
@shubhamdubey do you perform lookup based on the user id to look up all the user asset ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2023 11:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2023 12:28 AM - edited 12-16-2023 05:06 AM
@shubhamdubey this is the script i am using but when the form loads nothing happens on the serial number.
function onLoad() {
var openedForValue = g_form.getValue('opened_for'); // Replace 'opened_for' with the actual field name
if (openedForValue) {
var ga = new GlideAjax('MyScriptInclude');
ga.addParam('sysparm_name', 'getSerialNumbers');
ga.addParam('sysparm_opened_for', openedForValue); // Replace 'opened_for' with the actual field name
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('serial_numbers', answer); // Replace 'serial_numbers' with the actual field name
}
});
}
}
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getSerialNumbers: function() {
var openedForSysId = this.getParameter('sysparm_opened_for'); // Assuming 'opened_for' is a reference field to sys_user
var gr = new GlideRecord('alm_asset');
gr.addQuery('opened_for', openedForSysId); // Assuming 'opened_for' is a reference field to sys_user
var serialNumbers = [];
gr.query();
while (gr.next()) {
serialNumbers.push(gr.serial_number.toString());
}
return serialNumbers.join(', '); // Return a comma-separated list of serial numbers
}
});