- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @damodar
It is dot walk.
alm_hardware table --.Assigned to field is there
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you will require onChange client script on Employee name reference field and bring the hardward assigned to that person and then set it
Something like this with GlideAjax
Script Include: it should be client callable
var GetUserHardwareAjax = Class.create();
GetUserHardwareAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getHardwareByUser: function() {
var userSysId = this.getParameter('sysparm_user_sys_id');
var hardwareRecord = new GlideRecord('alm_hardware');
hardwareRecord.addQuery('assigned_to', userSysId);
hardwareRecord.query();
if (hardwareRecord.next()) {
return hardwareRecord.getUniqueValue();
}
return '';
},
type: 'GetUserHardwareAjax'
});
Client Script: onChange of employee
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('u_hardware'); // give here the correct field name
}
if (oldValue != newValue) {
var ga = new GlideAjax('GetUserHardwareAjax');
ga.addParam('sysparm_name', 'getHardwareByUser');
ga.addParam('sysparm_user_sys_id', newValue);
ga.getXMLAnswer(function(answer) {
if (answer != '')
g_form.setValue('u_hardware', answer); // give here the correct field name
else {
g_form.addInfoMessage('No hardware assigned to this user');
}
});
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @damodar
Try this (high level design) :
- Employee Name
- Type: Reference
- Reference Table: sys_user
- Reference qual condition: active=true^u_workday_integration=true
- Employee ID
- Type: String (Read-only)
- How to Populate:
- Set the Dependent question to the "Employee Name" field, and set the Dot walk path to employee_number /the field where you stored employee number (refer: Auto-populate a variable based on a reference type variable (Utah))
- Create an onChange Client Script on the Employee Name field using g_form.getReference() to fetch and set the value .Refer : https://www.servicenow.com/community/itsm-forum/auto-populate-fields-from-selected-user/m-p/604446
- Computer Name
- Type: Reference or String (Read-only)
- Reference Table: alm_hardware
- How to Populate:
- For Standard Forms: Create an onChange Client Script that triggers off the Employee Name field, pulling the primary computer field via a GlideAjax / getReference call.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thank you for marking my response as helpful.
Do you require any further help? Do let me know.
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @damodar ,
1) Mark the Computer Name field as Read-only.
2) Configure the field to use the value from Employee Name - Primary Laptop through dot-walking.
(This works only if a direct reference to the primary laptop exists on the User record.)
If the laptop is determined from asset assignment (Assigned to = User) and no dedicated "Primary Laptop" field exists.
Then use Client script(onchange) + Script Include :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
g_form.clearValue('u_computer_name');
if (!newValue)
return;
var ga = new GlideAjax('GetPrimaryLaptopAjax');
ga.addParam('sysparm_name', 'getPrimaryLaptop');
ga.addParam('sysparm_user_id', newValue);
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('u_computer_name', answer);
}
});
}
script include:
getPrimaryLaptop: function() {
var userSysId = this.getParameter('sysparm_user_id');
var gr = new GlideRecord('alm_hardware');
gr.addQuery('assigned_to', userSysId);
gr.setLimit(1);
gr.query();
if (gr.next())
return gr.getUniqueValue();
return '';
}
If my response helped mark as helpful and accept the solution.