- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 11:26 PM
Hi All,
I have written a catalog client script to display asset information based on requested for field
It is working fine when I do a 'Try It' in catalog item , but not in service portal.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 12:07 AM
@Priyanka145 Try the below script to clear if the user doesn't have any asset attached in alm_hardware table.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var rfor = g_form.getValue('requested_for');
var grd = new GlideRecord('alm_hardware');
grd.addQuery('assigned_to', rfor);
grd.query(setAssetInfo);
function setAssetInfo(grd) {
if (grd.next()) {
var asset = grd.asset_tag;
g_form.setValue('device_information', asset);
}else{
g_form.setValue('device_information', "");
}
}
}
Can you please mark my answers helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 11:32 PM
Hi @Priyanka145
Have you selected UI Type as ALL ? If not change it to ALL and try once.
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 11:38 PM
Yes @AnveshKumar M It is selected as All only. But still not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-20-2023 11:42 PM
Then try this following script in your onChange client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var rfor = g_form.getValue('requested_for');
var grd = new GlideRecord('alm_hardware');
grd.addQuery('assigned_to', rfor);
grd.query(setAssetInfo);
function setAssetInfo(grd) {
if (grd.next()) {
var asset = grd.asset_tag;
g_form.setValue('device_information', asset);
}
}
}
I'm assuming device_information variable is Single Line text, if it is Reference type to alm_hardware table, use the following script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var rfor = g_form.getValue('requested_for');
var grd = new GlideRecord('alm_hardware');
grd.addQuery('assigned_to', rfor);
grd.query(setAssetInfo);
function setAssetInfo(grd) {
if (grd.next()) {
var asset = grd.sys_id;
g_form.setValue('device_information', asset);
}
}
}
Please mark my answer helpful and accept as a solution if it helped 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2023 12:01 AM
Hi @AnveshKumar M It is a single line text, so the first script worked for me. Thanks.
If the asset is not assigned to any of the user in the requested for, if asset is empty. Then the older value has to be cleared. please let me know how it can be done