Is it possible to create a user from an interaction and re-link the new user to the interaction?

kristenmkar
Mega Sage

Good evening! 

 

I am currently helping to configure the Service Operations Workspace for our organization. To make it easier for the agents, I developed a UI action to create a user from the interaction if they do not exist. My script works fine to create the new user, but I was hoping to find a way to create the user and then link this new user back to the interaction record (so the agent doesn't need to re-select and find the created user).  Here is my current UI Action script (I currently have a button to "Create New User" displayed on the interaction form - it is a boolean field that needs to be checked to show the additional fields to fill out to create  the user)

 

//create new user
var userGr = new GlideRecord('sys_user');
if (current.u_user_not_found == true) {
    userGr.newRecord();
    userGr.setValue('first_name', current.opened_for.first_name);
    userGr.setValue('last_name', current.opened_for.last_name);
    userGr.setValue('user_name', current.opened_for.email);
    userGr.setValue('u_employee_type', current.opened_for.u_employee_type);
    userGr.setValue('email', current.opened_for.email);
    userGr.setValue('title', current.opened_for.title);
    userGr.setValue('phone', current.opened_for.phone);
    userGr.setValue('u_syscom', current.opened_for.u_syscom);
    userGr.setValue('u_edipi', current.opened_for.u_edipi);
    userGr.setValue('u_ech_iii', current.opened_for.u_ech_iii);
    userGr.setValue('u_business_area', current.opened_for.u_business_area);
    userGr.setValue('u_org', current.opened_for.u_org);
    userGr.setValue('u_org_code', current.opened_for.u_org_code);
    userGr.setValue('u_org_code_title', current.opened_for.u_org_code_title);
    userGr.setValue('u_branch_of_service', current.opened_for.u_branch_of_service);
    userGr.setValue('u_command_location', current.opened_for.u_command_location);
    userGr.setValue('u_remote_user', current.opened_for.u_remote_user);
    userGr.setValue('location', current.opened_for.location);
    userGr.setValue('department', current.opened_for.department);
    userGr.insert();
} else {
    gs.addInfoMessage("You must check " + "'User Not Found' " + "to Create a New User or remove referenced user in Opened For field.");
}
 
I tried something like the below to see if I grab the recid of the new user record and pull that into the call by field after its created, but so far I seem to be stuck at this point.
 
 var sys_idd = userGr.getValue('sys_id');
    current.opened_for == sys_idd;
 

Any ideas or am I crazy? 

Thank you! 




 

 

 

 

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

Hello @kristenmkar 

You can get the created user record sys_id like below:

var userGr = new GlideRecord('sys_user');
if (current.u_user_not_found == true) {
    userGr.newRecord();
    userGr.setValue('first_name', current.opened_for.first_name);
    userGr.setValue('last_name', current.opened_for.last_name);
    userGr.setValue('user_name', current.opened_for.email);
    userGr.setValue('u_employee_type', current.opened_for.u_employee_type);
    userGr.setValue('email', current.opened_for.email);
    userGr.setValue('title', current.opened_for.title);
    userGr.setValue('phone', current.opened_for.phone);
    userGr.setValue('u_syscom', current.opened_for.u_syscom);
    userGr.setValue('u_edipi', current.opened_for.u_edipi);
    userGr.setValue('u_ech_iii', current.opened_for.u_ech_iii);
    userGr.setValue('u_business_area', current.opened_for.u_business_area);
    userGr.setValue('u_org', current.opened_for.u_org);
    userGr.setValue('u_org_code', current.opened_for.u_org_code);
    userGr.setValue('u_org_code_title', current.opened_for.u_org_code_title);
    userGr.setValue('u_branch_of_service', current.opened_for.u_branch_of_service);
    userGr.setValue('u_command_location', current.opened_for.u_command_location);
    userGr.setValue('u_remote_user', current.opened_for.u_remote_user);
    userGr.setValue('location', current.opened_for.location);
    userGr.setValue('department', current.opened_for.department);
    var sysID = userGr.insert();  //store the sys_id
    current.opened_for = sysID; //assigning the newly created user record sys_id
    current.update(); //update the interaction record
} else {
    gs.addInfoMessage("You must check " + "'User Not Found' " + "to Create a New User or remove referenced user in Opened For field.");
}

 Is it okay for you guys to create user's via script? How do you handle users in your SN instance?

Thanks,
Murthy

View solution in original post

6 REPLIES 6

@kristenmkar 

So, you want to populate back the user details back to interaction.If yes which details you want to populat? Can you share any screenshots to know more better?

 

Thanks,
Murthy

No worries, I got it figured out! I appreciate all your help!