Module Arguments

Community Alums
Not applicable

I have a requirement to make a module that has a specific fixed filter. I know how to use javascript to get information in there, but the issue I'm running into is that it seems as if only one javascript entry per filter seems to work.

Basically I need a field to look like <Logged in user last name>, <Logged in user first name>

I expected it to look like:

&sysparm_fixed_query=primary_rep=javascript:gs.getUser().getLastName() + ", " + javascript:gs.getUser().getFirstName();

However the above doesn't work. I tried seeing if I could do variables, and that was just craziness. Anyone have any thoughts?

1 ACCEPTED SOLUTION

can you paste the screenshot of your script include ?

if script include as written in scoped application then you have to mention the scope name.

example: 

 

 &sysparm_fixed_query=last_name=javascript:new <your application name>.<script include name>().get()

 

for scoped application script include try with below code:

 

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

get: function(){
var id = gs.getUserID();
var gr = new GlideRecord('sys_user');
gr.get(id);
var fn =gr.first_name;
var ln = gr.last_name;
var op=fn+','+ln;
gs.info('result is'+op);

return op;
},

type: 'testina'
});

 

Arguments :  &sysparm_fixed_query=last_name=javascript:new x_43765_test.testina().get()

 

 

Note:  x_43765_test is my application which you will find from the "API Name" field from script include. 

View solution in original post

7 REPLIES 7

Harsh Vardhan
Giga Patron

did you try with script include ?

 

create one client callable script include and then you can call it in sysparm_fixed_query .

 

Sample: code:

 

var check = Class.create();
check.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	
	get: function(){
		
		var fn =gs.getUser().getFirstName();
		var ln = gs.getUser().getLastName();
		var op=fn+','+ln;
		gs.log('result is'+op);
		
		return op;
	},

    type: 'check'
});

 

In arguments :  &sysparm_fixed_query=short_description=javascript:new check().get()

 

Note: I tested with short_description field. you can add your field here. 

 

 

Community Alums
Not applicable

I did try this without success. Took your code and it still isn't working. This worked for you in your test? What version of ServiceNow did you test this in?

i am on madrid , i have used it on global scope , are you using it in scoped application ? 

 

can you put the log in your script include and check the result

Community Alums
Not applicable

getName is the script include name, it is client callable, I did set it to all application scopes, although its application is a different scope from Global, but so is the module.

 

org.mozilla.javascript.EcmaError: "getName" is not defined.
Caused by error in <refname> at line 1

==>   1: new getName().get()