Auto populate info on catalog item form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 08:37 PM
Hi,
I am a newbie to catalog item form configuration and the below areas holding me to complete the form.
1. Variable set - Reporting User Email/(would like to auto populate based on reporting user name from user table) - I have given the default value for 'Reporting User Email' as 'javascript:gs.getUser().getRecord().getValue('email');' but it still shows empty on the form.
2. Variables - Affected User Name / Affected User Department - would like to auto-populate the user department info from the user table upon selecting the 'Affected user name'.
Thanks.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 08:45 PM
Hi,
if you want to auto-populate default value when form loads based on logged in user then you need to use default value
If you wish to populate something on change then you would require onChange client script
What's your requirement?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 08:59 PM
Hi Ankur,
Below is the Onchange script used to populate Reporting user info.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('global.IncidentRecordProducerUtil');
ga.addParam('sysparm_name', 'getUserdata');
ga.addParam('sysparm_user', newValue);
ga.getXML(GetUserDetail);
function GetUserDetail(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var details = answer.split('|');
g_form.setValue('department', details[0]);
g_form.setValue('email', details[1]);
}
}
Can help on the onchange script to populate 'Affected User Department' info up on selecting the Affected user name? As I mentioned the Affected User Department is a separate variable created. So should we write a separate script for that one?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 09:11 PM
Hi,
onChange is written on which variable?
Can you share client script configuration screenshot and how the form looks
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2022 09:28 PM
Ankur,
Just a correction here.
Attached is the screenshot 'Default variable' to auto-populate the default value when form loads based on the logged-in user. Note that [Reporting user name/dept/email has been created as variable sets.
Attached is the form screenshot and need help in populating the affected user department info upon selecting the Affected user name which is created as variables in the form.