Hardware asset, auto populate field values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 09:38 PM
Hardware asset table: when we select an RITM id from the field 'request line' in Alm hardware asset table, then auto populate the state field as In Use, and assigned to field value same as requested_for of the selected RITM.
can anybody help me with this if I can achieve it using client script? and if I can then how?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 09:54 PM
Hi,
I would suggest few links and try the Client Script and GlideAjax to get this done.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 10:11 PM
answer from chatGPT。。。😀
- Create a script include and define a function that will perform the query, for example:
var MyScriptInclude = Class.create();
MyScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getHardwareAsset: function(rmNumber) {
var assetGr = new GlideRecord('alm_hardware');
assetGr.addQuery('request_line', rmNumber);
assetGr.query();
if (assetGr.next()) {
return {
state: 'In Use',
assigned_to: assetGr.getValue('requested_for')
};
}
return {};
}
});
- Save the script include and go to the form where you want to perform the query.
- Create a client-side script that calls the script include function using GlideAjax. For example:
function setHardwareAssetFields() {
var rmNumber = g_form.getValue('request_line');
var ga = new GlideAjax('MyScriptInclude');
ga.addParam('sysparm_name', 'getHardwareAsset');
ga.addParam('rm_number', rmNumber);
ga.getXML(onSuccess, onFailure);
function onSuccess(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer) {
g_form.setValue('state', answer.state);
g_form.setValue('assigned_to', answer.assigned_to);
}
}
function onFailure(response) {
alert('Error: ' + response);
}
}
- Add a client script to the form that calls the setHardwareAssetFields() function when the request_line field is changed.
Note that the getHardwareAsset() function returns an object with the state and assigned_to values, which are then set on the form using g_form.setValue(). Also, the rm_number parameter is passed to the script include function using ga.addParam().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 11:35 PM
can u tell me if i can configure this using onChange?