- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2023 07:48 AM
We have a record producer where one of the variables is a List Collector using the sys_user table. They would like to have posted in the Description of the ticket additional data for each user selected in the List Collector. We already have a Global script that cycles through each variable on a record producer to create the Description, so I don't want to alter that. My thought is to have a UI Script that runs on Submit to populate another variable (not visible on Portal) that would then appear in the Description, however, my scripting skills rank on the novice side.
So, the 2 variables in this effort would be:
List Collector: Affected Users (aff_users)
Multi Line Text: Affected Users Data (aff_users_data)
What I need to do is populate the aff_users_data variable with the Name (name), Email (email) and Business Phone (phone) of each person listed in the Affected Users (aff_users) variable. That I believe can be done with the On Submit UI Script. From there, our description generator would kick in to add the variable data to the Description.
I believe the script would have to contain some sort of loop against aff_users that would in turn add text to the aff_users_data variable. Roughly it would be:
For
each user in aff_users
Do
aff_users_data = aff_users_data + sys_user.name + " - " + sys_user.email + " - " + sys_user.phone + "/n"
I just don't know how to put this in proper code.
Sample of what would then get posted in the description field via our existing script:
Affected Users: Fred Flintstone, Barney Rubble, Wilma Flintstone
Affected Users Data:
Fred Flintstone - fred.flintsone@bedrock.com - 111-555-7452
Barney Rubble - barney.rubble@bedrock.com - 111-555-4411
Wilma Flintstone - wilma.flintstone@bedrock.com - 111-555-7452
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2023 09:32 AM
Hi @Rudy W ,
Please try the below solution and let me know if it works or not. I had given it a try and it worked in my PDI. May be you can try the same and see if it fixes what you are looking for.
For this you need to have a onSubmit Client script and an script inlcude.
Please find the Client Script code below: (see the attached screenshot for reference)
var userGa = new GlideAjax('GetListCollectorValue'); //script inlcude name
userGa.addParam('sysparm_name','getUserDetails'); //function name
userGa.addParam('sysparm_userDetails',g_form.getValue('aff_users')); //look up field
userGa.getXMLWait();
var usersList = userGa.getAnswer();
g_form.setValue('aff_users_data', usersList); //multi line field
Next create a script Include as shown below with the code (if you are using the own Name please change your GlideAjax accordingly). Also make sure that the client callable is checked.
Code:
getUserDetails : function(){
var userList = this.getParameter('sysparm_userDetails');
var userArray = userList.split(',');
var affectedUserList = "";
for (var users in userArray){
var userGr = new GlideRecord('sys_user');
userGr.get('sys_id',userArray[users]);
affectedUserList += userGr.name+' - '+userGr.email+ ' - '+ userGr.phone +'\n';
}
return affectedUserList;
},
Try this and let us know.
Mark Helpful and accept if it helps in solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 08:17 AM
Hi @Rudy W ,
I understood the problem now. It's not working in the portal. You can modify the client script as below. It will fix the issue.
if (g_scratchpad.isFormValid)
return true;
var userGa = new GlideAjax('GetListCollectorValue'); //script inlcude name
userGa.addParam('sysparm_name','getUserDetails'); //function name
userGa.addParam('sysparm_userDetails',g_form.getValue('aff_users')); //look up field
userGa.getXMLAnswer(myCallbackFunction);
return false;
function myCallbackFunction(answer) {
g_form.setValue('aff_users_data', answer);
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
Mark helpful if it helps in solving your problem.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-06-2023 09:32 AM
Hi @Rudy W ,
Please try the below solution and let me know if it works or not. I had given it a try and it worked in my PDI. May be you can try the same and see if it fixes what you are looking for.
For this you need to have a onSubmit Client script and an script inlcude.
Please find the Client Script code below: (see the attached screenshot for reference)
var userGa = new GlideAjax('GetListCollectorValue'); //script inlcude name
userGa.addParam('sysparm_name','getUserDetails'); //function name
userGa.addParam('sysparm_userDetails',g_form.getValue('aff_users')); //look up field
userGa.getXMLWait();
var usersList = userGa.getAnswer();
g_form.setValue('aff_users_data', usersList); //multi line field
Next create a script Include as shown below with the code (if you are using the own Name please change your GlideAjax accordingly). Also make sure that the client callable is checked.
Code:
getUserDetails : function(){
var userList = this.getParameter('sysparm_userDetails');
var userArray = userList.split(',');
var affectedUserList = "";
for (var users in userArray){
var userGr = new GlideRecord('sys_user');
userGr.get('sys_id',userArray[users]);
affectedUserList += userGr.name+' - '+userGr.email+ ' - '+ userGr.phone +'\n';
}
return affectedUserList;
},
Try this and let us know.
Mark Helpful and accept if it helps in solving your query.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 07:19 AM
I have tried this in both Tokyo and Rome and am receiving "There is a JavaScript error in your browser console"
I need to break away from working this to work a pressing issue.
Will get back as soon as possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 08:17 AM
Hi @Rudy W ,
I understood the problem now. It's not working in the portal. You can modify the client script as below. It will fix the issue.
if (g_scratchpad.isFormValid)
return true;
var userGa = new GlideAjax('GetListCollectorValue'); //script inlcude name
userGa.addParam('sysparm_name','getUserDetails'); //function name
userGa.addParam('sysparm_userDetails',g_form.getValue('aff_users')); //look up field
userGa.getXMLAnswer(myCallbackFunction);
return false;
function myCallbackFunction(answer) {
g_form.setValue('aff_users_data', answer);
var actionName = g_form.getActionName();
g_scratchpad.isFormValid = true;
g_form.submit(actionName);
}
Mark helpful if it helps in solving your problem.
Regards,
Johns
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2023 08:32 AM
AWESOME---
That did it.
I'm pretty good at reading code and understand what it is doing, just have trouble writing from scratch.
I really appreciate the assistance.