Need a script include function to pass parameter value in another drop down field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2016 03:14 AM
Hi All.
I need a script include to return back a value and populate the same in a drop-down field of an Incident form.
Below is the scenario,can one help me with e script include?
I have a custom Table "u_service_level_ci_mapping" with two fields "CI"(reference field of cmdb_ci) and "Service Level"(dropdown field with values as (Label = Not defined , value = 1), (Label = Gold , value = 2), (Label = Silver , value = 3), (Label = Bronze , value = 4) and Default value : (Label = Not defined , value = 1)
In "Incident" form we have OOB field as "Configuration Item"(cmdb_ci) and a custom dropdown field as "CI Service Level"(u_ci_service_level) with choice-labels & values same as "Service Level" field in "u_service_level_ci_mapping" table.
Requirement is I need a script include function to check the CI selected in "Incident" form in Configuration Item(cmdb_ci) field will check if the same CI exists in the custom table "u_service_level_ci_mapping" or not.
If CI exist in custom table, then in "Incident" form the "CI Service Level" field will be populated with same co-related value of "Service Level" filed in the custom table u_service_level_ci_mapping,that is mentioned against the CI.
If CI does not exist in custom table, then it will remain as dictionary default value i.e "Not Defined"
Can any one help out with any alike script for the same?
Also how will I pass the function name that returns the value (Gold/bronze/Silver) and populates the newly created drop down field "CI Service Level" in Incident form with the same.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2016 03:18 AM
Also without a Script Include can we leverage the Calculation field in Dictionary of Incident Form for the newly created field?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2016 08:32 AM
The approach I would take on this is to write an onChange client script on the incident's CI. When it changes, use a GlideAjax call to your script include to lookup and return the appropriate value. The client script's callback function can then set the choice field on the incident accordingly.
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-14-2016 12:28 AM
Hi Chuck and All,
Thanks a lot for your suggestion and here is what I landed up to.
Issue is the Client script some how cannot make the SI callable.If you see the OnChange client script second alert i.e alert(answer); is returning null to me hence the custom drop-down field in Incident form does not pick up the correct drop-down value mapped to the CI in the custom table u_service_level_ci_mapping.
Please help us in correcting the below scripts so that it works fine.Any help is hugely appreciated.
Client callable Script Include named as "CISlaresponsone"
var CISlaresponsone= Class.create();
CISlaresponsone.prototype = Object.extendsObject(AbstractAjaxProcessor, {
CIServiceLavel: function() {
alert('star 2 ');
var CI = this.getParameter('CIDetails');
var SLA = '0';
alert('papai ci name' + CI);
var grCI = new GlideRecord('u_service_level_ci_mapping');
grCI.addQuery('u_ci', CI);
grCI.query();
if (grCI.next()) {
SLA = grCI.u_service_level;
alert('papai SLA' + SLA);
}
return SLA;
},
});
On Change Client script named as "service level mapping" on Incident Table for field "Configuration Item(cmdb_ci)"
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var CIdetls = g_form.getValue('cmdb_ci');
alert('start' + CIdetls);
var ajax = new GlideAjax('CISlaresponsone');
ajax.addParam('sysparm_name', 'CIServiceLavel');
ajax.addParam('CIDetails', CIdetls);
//ajax.getXML(getResponse);
ajax.getXMLWait();
alert(ajax.getAnswer());
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//var answer =
alert(answer);
g_form.setValue('u_ci_service_level',answer);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-15-2016 06:08 AM
The first thing I note, is that you are using an alert() inside the script include. Script includes run server side. This could be causing your script include to crash and that's why you are getting the null or undefined value. Note: Always check the logs when things don't run properly. Try using gs.log() or gs.debug() instead.
We are covering GlideAjax on today's TechNow episode. Perhaps the answer will be discovered in there.
I invite you to watch episode 33 where we discuss this in detail.