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

1 ACCEPTED SOLUTION

@Chris Richie please replace the script include like below

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

View solution in original post

11 REPLIES 11

@Chris Richie please replace the script include like below

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

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'
});

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!

SumanthDosapati
Mega Sage
Mega Sage

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

 

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"