Auto Poupulate the asset assigned to the user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 01:04 AM
Hi,
I have the catalog form where there are 2 reference fields.
1. user_to_be_released - reference of sys_user table
2. computer_name - reference of alm_hardware table
Now i need to auto populate the asset assigned to the user( "user_to_be_release field") in computer_name field and below are the CS and script include which i have written. But i didnt get any values returned in computer_name field.
Can you please help me with this and is there any reference qualifier needs to added in computer_name field? Please give your suggestions, since i am new to scripting.
Client Script - written on computer_name and type is onChange
Script Include - client callable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 01:18 AM
I have added line 8 in script include only to query the asset which has model category as computer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 01:25 AM
Model category is reference field, so change that to
gr.addQuery('model_category.name', 'Computer');
Run the script include in a background script once with a hard coded value of the parameter you are passing to make sure that it returns the value you are expecting it to.
All alerts and info message to debug.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 01:34 AM
When I run the background script, it works , but computer name field is not populating any data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 01:40 AM
Sorry I didn't get you.
What is not working in background script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 01:39 AM
Hi @Aruna13,
Best practice is to run the same code in background script so you can retrieve the exact result as per requirement. Please try this code in background script below:
var gr = new GlideRecord('alm_hardware');
gr.addQuery('assigned_to', 'sys id of user which is assigned to any user');
gr.addQuery('model_category','pass the sysid of model category');// always user sys_id and try to avoid query by name
gr.query();
if (gr.next()) {
gs.info('Assest tag '+ gr.asset_tag); // returning the sys_id ensures that all fields in the reference are retrieved
}
Please accept my solution if it works for you and thumps up.
Thanks
Jitendra