Select User and list assets assigned (Catalog Form)

Chris Richie
Tera Contributor

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:

find_real_file.png

find_real_file.png

Allen Andreas
Tera Patron

Hello,

If you're wanting that field to get auto-populated, then you'd want to use an onChange Client Script and GlideAjax to use a Script Include, query the server, get the list of sys_ids, send it back to the client, and then set the value for that field to the list of sys_ids retrieved.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thank you for your answer, I'm a little inexperienced on doing that piece....can you guide/help me?

Hi @Chris Richie ,

 

> 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

 

Based one what you provided, I'm having an error on Line 6.  I don't think I understood.

var ScriptIncludeName = Class.create();
ScriptIncludeName.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    type: 'ScriptIncludeName'
});
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(',');
},

Screenshot:

find_real_file.png