have to populate the serial number of the asset associated to the user record

lakng
Tera Contributor

we have a catalog variable in one item, serial number

in this serial number, serial number of the asset of that user contains has to populate.

here am attaching the user record form, the asset attached to this user record. serial number will be in this asset table (alm_hardware)

so we need to have onchange client script and one script include.

by changing the user in the catalog item, the serial number has to change based on the user.

find_real_file.pngfind_real_file.png

in this variable, the serial number has to populate 

find_real_file.png

1 ACCEPTED SOLUTION

add alert(g_form.getValue('user')); and check what is the user.

Then go to alm_hardware.list and there add filter assigned_to and put this user and check the no. of entries it has.

Compare it with the output of SI

View solution in original post

15 REPLIES 15

asifnoor
Kilo Patron

Hi,

 

In alm_hardware, you can find the asset. What is the relationship between user and asset? ARe you considering owned_by or assigned_to or managed_by field in alm_hardware table?

Secondly, what if the user has multiple assets, which asset serial number do you want to fill in? What are the fields you have in the catalog item?

Mark the comment as a correct answer and helpful if it helps.

lakng
Tera Contributor

What is the relationship between user and asset? 

every user will be having assets with him. so we have see what assets he has been using by looking in to the user record.

ARe you considered owned_by or assigned_to or managed_by field?

assigned_to

all serial number have to display separated with commas

i have one field in the catalog item, which is serial_number. this field has to fill with the serail number associated to that user (submitted_by).

if the submitted by changes, then associated asset serial numbers has to display.

basically its onchange

 

lakng
Tera Contributor

this is my script include which is not working 

var userInfoAjax = Class.create();

userInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getAssets: function(){

var returnString = 'The serial registered for the user is ';
var arr = [];
var UserId = this.getParameter('sysparm_user_name');
var gr = new GlideRecord('alm_hardware');
gr.addQuery('assigned_to',UserId);
gr.query();
while(gr.next()){
arr.push(gr.getValue('serial_number'));
}

returnString = returnString + arr.join(',');
return returnString;
},

type: 'userInfoAjax'
});

 

and this is the client script:

on change : sub_name

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

// Call the GA function
var ga = new GlideAjax('userInfoAjax');
ga.addParam('sysparm_name', "getAssets");
ga.addParam('sysparm_user', g_form.getValue('user'));
ga.getXMLAnswer(function(answer){
g_form.setValue('the_serial_registered_for_the_user_is', answer);

});
}

Hi,

The parameter you are sending is wrong.

In your SI, change this line

var UserId = this.getParameter('sysparm_user_name');

TO

var UserId = this.getParameter('sysparm_user');

Mark the comment as a correct answer and helpful once worked.