- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-31-2024 11:50 PM - edited 10-31-2024 11:53 PM
Hi All,
We are using order guide - Employee Transfer Request
In that Asset Return is 1 item where all the assets of Requested for should be auto selected
I am using this script but its not working. The data is not getting auto selected on portal.
List collector field : ar_pc_request
No Reference qualifier
Only Variable attributes are there : ref_auto_completer=AJAXTableCompleter,ref_ac_columns=display_name;serial_number;model
Script Include : Client Callable
sendAssetData: function() {
var user = this.getParameter('sysparm_user');
// gs.addInfoMessage("user received : " + user);
var hardwares = [];
var grHardware = new GlideRecord('alm_hardware');
grHardware.addQuery('assigned_to', user);
grHardware.query();
while (grHardware.next()) {
//gs.addInfoMessage('inside while');
hardwares.push(grHardware.sys_id.toString());
}
return hardwares.toString();
},
Client script : On Change : Requested for (a variable from Variable set)
if (isLoading) {
return;
}
if (newValue === '') {
g_form.clearValue('ar_pc_request'); //your variable name
}
var ga = new GlideAjax('getAssetData');
ga.addParam('sysparm_name', 'sendAssetData');
ga.addParam('sysparm_user', newValue);
ga.getXML(populateValues);
function populateValues(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// var arr = answer.split('||');
// g_form.addInfoMessage("answer : "+arr[0]);
g_form.setValue('ar_pc_request', answer);
}
Result:
Kindly let me know if i m doing any mistake in script as its not working in order guide item
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 09:10 PM
The problem was not with the code but with the type of client script. Instead of change client script, on load client script is working. Then the issue is resolved.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 12:45 AM
Hi @yyasaswini
Consider using gs log for debugging purposes within the Script Include to help identify any issues. Additionally, ensure that the Script Include is returning the expected values.
Thank you
Eshwar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2024 01:48 AM
Hi @yyasaswini ,
Your code does not have any issue, i tried it in my pdi, its working as expected.
You can check field name "ar_pc_request", hope this is correct name.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 09:10 PM
The problem was not with the code but with the type of client script. Instead of change client script, on load client script is working. Then the issue is resolved.