What is the understanding of the code if(grUser.get(this.getParameter('sysparm_user')))

ServiceNow Use6
Tera Guru

Hi @Mark Roethof ,

Thank you so much for being patient. I have one last question, please. What is the meaning of 

if(grUser.get(this.getParameter('sysparm_user')))

I know that we are passing the value of sysparm_user which is the newValue from client script. But what is happening?

var getUserPropertiesAjax = Class.create();
getUserPropertiesAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	
	get_phone : function() {
		var grUser = new GlideRecord('sys_user');

		if(grUser.get(this.getParameter('sysparm_user'))) { //My Doubt Mark
			return grUser.getValue('phone');
		}
	},
	
    type: 'getUserPropertiesAjax'
	
});

Regards

Suman P.

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

When using a (Catalog) Client Script with GlideAjax, you would use at least:

sysparm_name

So something like:

gaPhone.addParam('sysparm_name', 'get_phone');

Function name will be get_phone.

You can also pass along values, which you could use within your Script Include. Actually this can have any name, though common naming convention would be that it just starts with "sysparm_"

So in this example:

gaPhone.addParam('sysparm_user', newValue);

This way you would pass the sys_id of the user reference (I believe you mentioned caller_id?)

Within the Script Include, you can get your hands on that passed in values, by using:

this.getParameter('...')

So in this case:

this.getParameter('sysparm_user')

This would represent the function name.

The part with if(grUser.getis just part of the GlideRecord get being performed. This could also have been a GlideRecord query with addQuery etc, though not necessary here.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

3 REPLIES 3

Mark Roethof
Tera Patron
Tera Patron

Hi there,

When using a (Catalog) Client Script with GlideAjax, you would use at least:

sysparm_name

So something like:

gaPhone.addParam('sysparm_name', 'get_phone');

Function name will be get_phone.

You can also pass along values, which you could use within your Script Include. Actually this can have any name, though common naming convention would be that it just starts with "sysparm_"

So in this example:

gaPhone.addParam('sysparm_user', newValue);

This way you would pass the sys_id of the user reference (I believe you mentioned caller_id?)

Within the Script Include, you can get your hands on that passed in values, by using:

this.getParameter('...')

So in this case:

this.getParameter('sysparm_user')

This would represent the function name.

The part with if(grUser.getis just part of the GlideRecord get being performed. This could also have been a GlideRecord query with addQuery etc, though not necessary here.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Any more info needed on this topic? Let me know.

Else please close the topic. Tnx.

Kind regards,
Mark

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Shubham Sinha5
Mega Expert

Whenever there is sysparm_ in the start of anything, it is getting passed as parameter from somewhere as you can see the pattern of servicenow url

So that is kind of pattern the developer often uses when defining parameters anywhere

 

https://dev-----.service-now.com/sys_user_list.do?sysparm_query=user_name!%3DNULL&sysparm_first_row=1&sysparm_view=

 

Hope it helps!