- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 12:45 PM
Script to autopopulate the owner name for mailbox in the catalog item -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.setValue('Owner','');
return;
}
var caller = g_form.getReference('mb', doAlert);
}
function doAlert(caller) {
g_form.setValue('owner', caller.u_owner);
}
Task at hand -
once the user submits the ticket with all this information through a catalog item, replace owner1 with owner2 and close the ticket. so basically, find Mailbox1 in reference table and replace the existing owner of it to the variable value of new owner field from the catalog item.
I am fairly new to this , so some of it makes sense to make me but not all of it.
Issues faced - I have tried both business rule and script by executing below script but i am unable to find any clear error messages(maybe I am looking at the wrong places)
question - In glide record should i be giving the reference table name because thats where i want the update to happen or sys_user because the owner name resides there?
--------------------------------
var user_ref = current.variable.owner.getValue(); //get the sys_id of the Owner
var userManValue = current.variables.newowner.getValue(); //get the sys_id of the new Owner
var userManDisplayValue = current.variables.newowner.getDisplayValue(); //get the displayValue of the new owner
var userU = new GlideRecord('reference table 1');
if (userU.get(user_ref)){ //get user record using the owner sys_id
userU.setValue("owner",userManValue,userManDisplayValue); //set the owner's value and displayValue (prevents roundtrip to server)
userU.update(); //update record
}
Please help me with this, it is getting pretty urgent that i resolve this
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2022 09:46 AM
Ok..Got it...Please try below code
var user_ref = current.variables.owner.getValue(); //get the sys_id of the Owner
var userManValue = current.variables.newowner.getValue(); //get the sys_id of the new Owner
gs.info('------------user_ref -'+user_ref);
gs.info('-------------userManValue -'+userManValue);
var userU = new GlideRecord('u_shared_mailbox');
userU.addQuery('u_owner',user_ref);
userU.query();
if (userU.next())
{ //get user record using the owner sys_id
userU.setValue("u_owner",userManValue);
userU.update(); //update record
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2022 10:06 AM
You sir are a champion 🙂
thank you for hand holding me for this one.
it worked and the value is changed.
Few additional requirements that i have are -
- once the RITM is raised, it goes for approval
- once approved, a task is created
- once the task is created, the owner is updated and task is closed
I am going to work on these on my own and only if i am stuck somewhere, i will bother you again 🙂
you are a rockstar!!!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 10:18 AM
Can you please try below code?
var user_ref = current.variables.owner.getValue(); //get the sys_id of the Owner
var userManValue = current.variables.newowner.getValue(); //get the sys_id of the new Owner
var sharedmailbox = current.variables.shared_mailbox.getValue();//get the sys_id of mailbox selected
gs.info('------------user_ref -'+user_ref);
gs.info('-------------userManValue -'+userManValue);
var userU = new GlideRecord('u_shared_mailbox');
if (user_ref)
userU.addQuery('u_owner',user_ref);
userU.addQuery('sys_id',sharedmailbox);
userU.query();
if (userU.next())
{ //get user record using the owner sys_id
userU.setValue("u_owner",userManValue);
userU.update(); //update record
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 01:55 PM
Hi Sanjiv,
I ran the updated one but no Joy.
I dont know if this is the correct way to identify any issue but i ran the script in system definition> Scripts-Background and i see the error below -
Evaluator: com.glide.script.RhinoEcmaError: Cannot read property "variables" from null script : Line(1) column(0) ==> 1: var user_ref = current.variables.owner.getValue(); //get the sys_id of the Owner 2: var userManValue = current.variables.newowner.getValue(); //get the sys_id of the new Owner 3: var userU = new GlideRecord('u_shared_mailbox'); 4: if (userU.get(user_ref))
This might be completely irrelevant but i am just grasping at straws now 🙂
Is there any other way to identify how the script is running?
thank you so much for your help with this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 02:00 PM
Can you confirm, you are running this Business rule on requested item table? Also added few debug statements to check if we are getting the right values
var user_ref = current.variables.owner.getValue(); //get the sys_id of the Owner
var userManValue = current.variables.newowner.getValue(); //get the sys_id of the new Owner
gs.addInfoMessage('user_ref -'+user_ref);
gs.addInfoMessage('userManValue -'+userManValue);
var userU = new GlideRecord('reference table 1');
if (userU.get(user_ref))
{ //get user record using the owner sys_id
userU.setValue("u_owner",userManValue);
userU.update(); //update record
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 02:36 PM
Hey Sanjiv,
I was running this as a workflow script. will it not work there?
I can create a business rule and run it on request item table and see if that solves the problem.
what do you suggest?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 02:45 PM
Workflow script is fine, if the workflow is running on requested item table. I have added another debug statement. Please check the logs, if you are getting values there.
var user_ref = current.variables.owner.getValue(); //get the sys_id of the Owner
var userManValue = current.variables.newowner.getValue(); //get the sys_id of the new Owner
gs.info('------------user_ref -'+user_ref);
gs.info('-------------userManValue -'+userManValue);
var userU = new GlideRecord('reference table 1');
if (userU.get(user_ref))
{ //get user record using the owner sys_id
userU.setValue("u_owner",userManValue);
userU.update(); //update record
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2022 03:41 PM
I created a business rule and ran it, the business rule is getting called but i think the script is not working. see logs above
thanks again for your help Sanjiv