Update User profile on Catalog Item submission from Service Portal.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 08:56 AM
Hello,
I am trying to update the User profile values when a catalog form is submitted. I am using a Multiple Variable Set of current User values, then if the user changes any values when the form is submitted the values should be updated for the identified user (u_user). Code is not working and I am failing to see what is wrong. I am getting a good user sys_id but the script doesn't appear to enter while loop.
function onSubmit() {
// Update User Profile onSubmit.
var requestFor = g_form.getValue('u_user');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', requestFor);
gr.query();
while (gr.next()) {
alert('Entered while');
gr.email = gr.getValue('u_user_email');
gr.location = gr.getValue('u_user_location');
gr.manager = gr.getValue('u_user_manager');
gr.phone = gr.getValue('u_user_business_phone');
gr.setWorkflow(false); // Turn off notifcations.
gr.update();
}
}
onSubmit();
Thank you,
-Wesley
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 09:10 AM
Hi,
please use workflow run script to update and don't use onSubmit
I hope you must be having variables to hold individual attributes like u_user_location, u_user_business_phone
use workflow run script
I assume all these are the variables on your catalog form which user will change
u_user, u_user_email, u_user_location, u_user_manager, u_user_business_phone
// Update User Profile onSubmit.
var requestFor = current.variables.u_user;
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', requestFor);
gr.query();
if(gr.next()) {
gr.email = current.variables.u_user_email;
gr.location = current.variables.u_user_location;
gr.manager = current.variables.u_user_manager;
gr.phone = current.variables.u_user_business_phone;
gr.setWorkflow(false); // Turn off notifcations.
gr.update();
}
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
01-18-2022 09:29 AM
Trying to do script in Multi-Variable Set client script during submission or could do onChange on the catalog form vs. updating all workflows behind each catalog item. Much more work to update each catalog item's workflow. Hope this makes sense.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 07:18 PM
Can you share form screenshot?
What is the name of MRVS? which all variables are there inside it?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2022 09:11 AM
You're trying getValue instead of setValue is that right ?
write this in flow designer or workflow please
Hit helpful or mark correct if it was 🙂