Auto-Populate the Assigned to field if similar Serial number is found in system

Preksha Kapoor
Tera Contributor

Hi All,

 

we want to auto populate a singleline text box field with the assigned user name if the serial number entered in the form already exist

 

Attached is the screenshot of the same

 

PrekshaKapoor_1-1742396308796.png

 

8 REPLIES 8

Hi @Preksha Kapoor ,

 

Did you check my response?

 

If my response helped, please hit the Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Rohit

Ankur Bawiskar
Tera Patron
Tera Patron

@Preksha Kapoor 

you can have onChange on Serial Number variable and query alm_asset table and bring the Assigned to user

Something like this

Script Include: It should be client callable

var AssetUtils = Class.create();
AssetUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getAssignedTo: function() {
        var assetGR = new GlideRecord('alm_asset');
        assetGR.addQuery('serial_number', this.getParameter('sysparm_serialnumber'));
        assetGR.query();
        if (assetGR.next()) {
            return assetGR.assigned_to.sys_id;
        }
        return '';
    },

    type: 'AssetUtils'
});

AnkurBawiskar_0-1742399699167.png

 

Client script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var ga = new GlideAjax('AssetUtils');
    ga.addParam('sysparm_name', 'getAssignedTo');
    ga.addParam('sysparm_serialnumber', newValue);
    ga.getXMLAnswer(function(response) {
        if (response) {
            g_form.setValue('assigned_toVariable', assignedTo);
        } else {
            g_form.clearValue('assigned_to');
            g_form.addErrorMessage('No asset found with the provided serial number.');
        }
    });
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Preksha Kapoor 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Preksha Kapoor 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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