- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 04:49 AM
Hi,
I have the variable 'computer name' of type string in my 'create incident' record producer. I have the field 'u_computer_name' of type string on sys_user table. How can I set the default value of this variable inside the record producer to be like computer_name of the current login user when loading the record producer?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 05:30 AM
Hi @Alon Grod ,
You need to write an Client Script + Script Include to achieve this
Do as something like this onLoad
Client Script
function onLoad() {
var ga = new GlideAjax('loggedUserData');
ga.addParam('sysparm_name', 'name');
ga.getXML(callback);
}
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//put this answer in your variable
}
In Script Include
var loggedUserData= Class.create();
loggedUserData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
name: function () {
return gs.getUser().u_computer_name;
}
});
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 07:01 AM
this should work fine
javascript: gs.getUser().getRecord().getValue('u_computer_name');
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 05:30 AM - edited 02-06-2023 05:36 AM
Set the default value of your variable to:
javascript: gs.getUser().getRecord().getValue('u_computer_name')

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 05:30 AM
Hi @Alon Grod ,
You need to write an Client Script + Script Include to achieve this
Do as something like this onLoad
Client Script
function onLoad() {
var ga = new GlideAjax('loggedUserData');
ga.addParam('sysparm_name', 'name');
ga.getXML(callback);
}
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//put this answer in your variable
}
In Script Include
var loggedUserData= Class.create();
loggedUserData.prototype = Object.extendsObject(AbstractAjaxProcessor, {
name: function () {
return gs.getUser().u_computer_name;
}
});
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 05:54 AM - edited 02-06-2023 08:31 AM
It will display the value ,the moment you loaded the page,Please write the code in default value of record producer computer name field as below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2023 07:01 AM
this should work fine
javascript: gs.getUser().getRecord().getValue('u_computer_name');
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 02:45 AM
Hi Ankur,
I have tried this for setting the "Department" in Default value.Its showing as both string and numeric format like 'f32r539ni3243info58' this.help me how to resolve this.It has to get display in string format not in AlphaNumeric format.