Not able to set values to list collector from script include

Tanwir Singh11
Tera Expert

Hi All,

I am filtering out the values from list collector (list_of_devices) which is referencing alm_asset table and another reference is location. So, i want to show only those assets which are from that location.

I have created a client script and a script include. I am able to return the sys_id from script include to client script but not able to set them in list collector. Below is my code:

Script include:

 getSiteAssets: function() {
		var arr_name = [];
                var OtoO = this.getParameter('sysparm_type');

                var ast = new GlideRecord('alm_asset');
                ast.addQuery('location', OtoO);
                ast.query();
                while (ast.next()) {                    
					arr_name.push(ast.getUniqueValue());
				}                
                return arr_name.toString();
            },

 

Client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var ga = new GlideAjax('SiteDependentAssets');
    ga.addParam('sysparm_name', 'getSiteAssets');
    ga.addParam('sysparm_type', newValue);
    ga.getXML(parseData);

    function parseData(response) {
        var answer = response.responseXML.documentElement.getAttribute('answer');
		alert(answer);
        g_form.setValue('list_of_devices', answer);
    }
}

 

Please help.

1 ACCEPTED SOLUTION

inform business that this is not feasible.

Either tell them

1) you will filter the list collector based on location and let user select the location to right bucket

OR

2) you will set the right bucket with the available assets for location selected and let user remove if they wish to

If my response helped you please mark it correct to close the question so that it benefits future readers as well.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

24 REPLIES 24

You have to push the sys_ids in the arry not the display name

 arr_name.push(ast.display_name.toString());

 

  arr_name.push(ast.sys_id.toString());

yes, corrected that and still not working. 

 

I have updated the final code in the question.

The code should be correct after that. Are you sure you selected a location that has assets? 

Yes, please have a look at screenshot below:

 

find_real_file.png

I selected TOR1 and it has 4 records. I am getting 4 sys_id's from script include. Please have a look at that too bewow:

 

find_real_file.png

Ankur Bawiskar
Tera Patron
Tera Patron

@Tanwir Singh 

there are 2 things

1) Filtering

Since you want to filter then no need to use onChange client script

Let list collector filter based on location variable

Advanced ref qualifier

javascript: 'location=' + current.variables.locationVariable;

Variable attributes

ref_qual_elements=locationVariable

find_real_file.png

OR

2) setting the list collector based on location variable

If you wish to auto-populate then refer my blog and it would work in both native + portal

Dynamically set list collector on change of variable

if my blog helps please mark it helpful and also bookmark it

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader