can you pls clarify the requirement

damodar
Tera Contributor

damodar_0-1781007877915.png

how to do the 3rd step can you clarify clearly 

3 REPLIES 3

Dr Atul G- LNG
Tera Patron

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]

****************************************************************************************************************

Ankur Bawiskar
Tera Patron

@damodar 

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'
});

55.png

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Tanushree Maiti
Tera Patron

Hi @damodar 

 

Try this (high level design) :

  1. Employee Name
  • Type: Reference
  • Reference Table: sys_user
  • Reference qual condition: active=true^u_workday_integration=true

 

  1. Employee ID
  1. 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.
Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti