Auto populate description field in a catalog item when redirected from the Catalog item link in Virtual Agent

Nikita35
Kilo Guru

hello Experts,

I have one requirement in which I need to provide the link of catalog item in virtual agent so that when user will click on the link, it will redirect to a catalog item.

Now this catalog item has a field called description which should be automatically populated with some text - "I need access to XYZ".

Redirecting to catalog item seems fine to me. But how Can I achieve this auto population of description.

Regards

1 ACCEPTED SOLUTION

Hi Nikita,

so do one thing; as part of approach we are adding extra parameter in the url which is "sysparm_virtualagent"

So use below script to know whether the url contains this string; if yes the set the value

updated script below; use UI type as ALL

function onLoad() {
	//Type appropriate comment here, and begin script below
	var url = top.location.href;
	var index = url.indexOf("sysparm_virtualagent");	 
	if(index >= 0)
		g_form.setValue('description','I need access to XYZ');
}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

17 REPLIES 17

Nikita35
Kilo Guru

Any suggestions on this?

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nikita,

So in catalog item you need to auto-populate this text 

I need access to XYZ

you can use onload client script on catalog item and set the value using g_form

g_form.setValue('description','I need access to XYZ');

check this link as well

https://docs.servicenow.com/bundle/newyork-performance-analytics-and-reporting/page/administer/virtu...

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Hi Ankur

Thank you for your reply.

Creating an onload client script will run everytime when the catalog item form is opened.

I want the text to be displayed in the description only when the link is redirected from the virtual agent.

Is there any way to do it ?

Hi Nikita,

yes you can make the onload script to set the value to run when something is present or not in the URL

how are you redirecting ? what is the url you are getting in the onload client script when the catalog item is being opened from virtual agent

Can you share that?

Regards

Ankur

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