0% found this document useful (0 votes)
6 views7 pages

Script include

Doc 1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Script include

Doc 1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Script Include:- Concept With UseCase

My goal is not just to solve scenario-based questions but


to help you develop the mindset needed to approach such
requirements. I hope this will benefit you, if you're new to
the ServiceNow field ​
or have prior experience. if you have any confusion ,you
can check it once…….

#UseCase 1:-​
How can I configure the error message for an existing
asset tag in ServiceNow to display: "An asset with this tag
already exists"?

So here asset tag is available on “alm_hardware” table we


will have to query on this table.

Script Include​

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

checkDuplicate: function() {
// Retrieve parameters passed from the client script
var fieldValue =
this.getParameter("sysparm_field_value");

// Query the 'alm_hardware' table for duplicates


var gr = new GlideRecord('alm_hardware');
gr.addQuery('asset_tag', fieldValue);
gr.query();

if (gr.next()) {
return 'true'; // Record found
}
return 'false'; // No record found
},

type: 'AssetValidation'
});

Client Script:- ​

function onChange(control, oldValue,
newValue, isLoading, isTemplate) {
if (isLoading || newValue === ''||
newValue === oldValue) {
return;
}
//passes the script include name
var ga = new
GlideAjax('AssetValidation');
//Call the server side function
ga.addParam('sysparm_name',
'checkDuplicate');
//Passes the new field value (newValue) to
the server for validation

ga.addParam('sysparm_field_value',newVa
lue);
ga.getXMLAnswer(function(response) {

var result = response;


if (result === 'true') {

g_form.showFieldMsg('asset_tag', 'An asset


with this tag already exists.','error');
} else {
g_form.hideFieldMsg('asset_tag', true);
}

Thank you​

You might also like