- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 12:37 AM
Hi All,
I want to auto populate "asset_tag" value from asset table(alm_hardware) for selected user "requested_for" in service request. Could you please provide me the sample code to achieve this.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2018 04:01 AM
Hi Josmad,
The field you are trying to set is a reference field right? or it is a string field.
If it is a reference field it can hold only 1 value
if it is a string field then do you want to populate all the asset tags with comma separated in that field.
If yes then update script as below
getDetails: function(){
var arr = [];
var sysId =this.getParameter('sysparm_sysId');
var gr = new GlideRecord('alm_hardware');
gr.addQuery('assigned_to', sysId);
gr.query();
while(gr.next()){
arr.push(gr.asset_tag.toString());
}
if(arr.length > 0)
return arr.toString();
else
return '';
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 12:47 AM
Hi Josmad,
What relationship exist between user and alm_hardware table?
Is there a field on alm_hardware which refers to user table based on which you can fetch the asset tag?
Also will there be only 1 record in alm_hardware table for a user?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 04:27 AM
"assigned_to" is the field name in "alm_hardware" which refers to the user table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 04:34 AM
Hi Josmad,
Write onChange on requested_for call a script include through GlideAjax and send the requested_for value
Query alm_hardware table with this against assigned_to value and send asset_tag from script include function, then set the value.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2018 05:05 AM
Can you please provide me code if you have any sample codes. It could be helpful to me.