
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 08:55 AM
Hello - I'm working on an offboarding form and would like it that when a user is selected, it will output their list of assets and eventually list it in the RITM and/or TASK Description.
Currently I have it setup as a list collector which the user filling out the form needs to select the available assets, but I would prefer it would simply list all of them and attach to record. Can you assist me with that please?
Here is a few screenshots:
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 10:20 AM
You need to write your function always inside prototype like below
var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateAssets: function() {
var arr = [];
var gr = new GlideRecord("alm_hardware");
gr.addQuery('assigned_to', this.getParameter('sysparm_employee'));
gr.query();
while(gr.next()) {
arr.push(gr.sys_id.toString()); //give your owner field name here
}
return arr.join(',');
},
type: 'ScriptIncludeName'
});
Please mark my response correct or helpful if it helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 10:20 AM
You need to write your function always inside prototype like below
var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateAssets: function() {
var arr = [];
var gr = new GlideRecord("alm_hardware");
gr.addQuery('assigned_to', this.getParameter('sysparm_employee'));
gr.query();
while(gr.next()) {
arr.push(gr.sys_id.toString()); //give your owner field name here
}
return arr.join(',');
},
type: 'ScriptIncludeName'
});
Please mark my response correct or helpful if it helps you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 11:47 PM
Modify the script as below
var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {
populateAssets: function() {
var arr = [];
var gr = new GlideRecord("alm_hardware");
gr.addQuery('assigned_to', this.getParameter('sysparm_employee'));
gr.query();
while(gr.next()) {
arr.push(gr.sys_id.toString()); //give your owner field name here
}
return arr.join(',');
},
type: 'ScriptIncludeName'
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 10:31 AM
Hi,
It's very unfortunate that you didn't attempt this yourself. I included a cheat sheet that literally guides you through it.
My goal is for you to learn, not be provided exact script that does what I described above.
This doesn't help you in the long run. You could have attempted yourself and we work with you through this.
Best of luck with the platform!
-Allen
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 09:27 AM
Hi
> Open 'Maintain items' from left navigator
> Open you catalog item record
> In Related lists, go to client scripts and click new
> Select type as OnChange and variable as Employee name and UI Type as All
> Write below script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax("ScriptIncludeName"); //give your client callable script include name which you are going to create in next steps
ga.addParam('sysparm_name', 'populateAssets');
ga.addParam('sysparm_employee', newValue);
ga.getXML(callback);
}
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue("assets_assigned",answer); //update your assets assigned variable name here
}
> save
> Open script Includes from left navigator and click on new
> Give a name and tick the client callable check box
> Update the script include name in above client script in glideAjax line
> Some script will be auto generated.. in that in line number 5 copy paste the below code
populateAssets: function() {
var arr = [];
var gr = new GlideRecord("alm_hardware");
gr.addQuery('assigned_to', this.getParameter('sysparm_employee'));
gr.query();
while(gr.next()) {
arr.push(gr.sys_id.toString()); //give your owner field name here
}
return arr.join(',');
},
Mark as correct and helpful if it solved your query.
Regards,
Sumanth

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2022 10:21 AM
Getting an error on Line 6. Didn't really understand the last step "Some script will be auto generated.. in that in line number 5 copy paste the below code"