How to auto populate the Application name in catalog item

Arun91
Tera Contributor

Hi Team,

We have created a catalog item form which contains requested for and application name.

Requested for field is referencing sys_user table and application name field is querying cmdb_ci_appl table.

I have another two custom tables named as xxx and yyy.

cmdb_ci_appl table has all the application that is mapped with table xxx. In table yyy the data which is present in table xxx along with the assigned user will present in table yyy

Now my requirement is when user is submitting the request, user will select the requested for based on the requested for input it should display the application name details.

 

Kindly help me on this.

7 REPLIES 7

AshishKM
Kilo Patron
Kilo Patron

Hi @Arun91 , 

Write catalog client script [ onLoad or onChange ] whichever is applied. 

In the script, read the user from yyy and get the match record from xxx and read the application from cmdb_ci_appl.

Draft some script code and share so we can help.

 

-Thanks,
AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Mani A
Tera Guru

Sample code:

 

Write reference qualifier on application name variable like 

Javascript: new scriptInclude().fName(current.varibales.requestedFor);

 

In script include function..

function :fName(user) 

{

var x =new GlideRecord("yyyy")

x.addEndodedQuery("assigned"+user+'^applicationsISNOTEMPTY");

x.query()

var y=[]:

y.push( x.applications.toString());

 

var app=new GlideRecord("cmdb_ci_app")

app.addEncodedQuery("app.sys_idIN"+y)

app.query();

Var finalArr=[];

finalArr.push(app.sys_id.toString();

return finalArr.join(",");

Arun91
Tera Contributor

Hi,

I have tried it but still I am able to see all the application.

Code which I have written:

var r = Class.create();
r.prototype = {
    initialize: function() {
    },
    TypeAccessRoles1: function(u_user_name) {
        var roles = [];
       
        var x = new GlideRecord('u_uam_application_user_roles');
        x.addEncodedQuery('u_user_name^u_app_nameISNOTEMPTY');
        x.query();
        var y = [];
        y.push(x.u_app_name.toString());
        var app = new GlideRecord('cmdb_ci_appl');
        app.addEncodedQuery("app.sys_idIN"+y);
        app.query();
       
        var finalArr=[];
        finalArr.push(app.sys_id.toString());
        return finalArr.join(",");
},
    type: 'r'
};

Mani A
Tera Guru

I had given sample code..please do changes with correct field names..

 

where are you passing user_name

parameter in function ? 

typeAccessRoles1: function (user_name)

X.addEndodedQuery("u_user_name="+user_name+"^u_app_nameISNOTEMPTY");

x.query()

While(x.next())

Also use while loop after query statement

 

next in second gliderecord useCorrectfiedlName for app..

also use while loop after query statement..

 

At the end return "sys_idIN"+finalArr.join(",");