- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 02:22 AM
I have a custom table with incident number on it, requirement is to display below fields in the info message once the incident number is changed :
Incident Details
incident number,
short description
priority
Assigned group
Assigned to
Associated Problems:
Problem number
Problem short description
Problem Assigned Group
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 02:32 AM
Hi Uma,
Create a SI which accepts the incident number as a parameter, fetches the incident details and send it as JSON object back to client script.
Then in the client script, write on change client script on the incident number and call this SI. Based on the response, parse it and display them on top of the form using g_form.addInfoMessage.
You can also do with g_form.getReference, but best is to go with SI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 02:31 AM
Hi,
use onchange client script for this
Is the incident field a reference; use g_form.getReference() with callback
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var incident = g_form.getReference('u_incident', getDetails);
function getDetails(incident){
var str = incident.number + ' ' + incident.short_description + ' ' + incident.priority + ' ' + incident.assignment_group + ' ' + incident.assigned_to;
// for getting problem you need to do glide ajax
}
g_form.addInfoMessage(str);
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2019 02:32 AM
Hi Uma,
Create a SI which accepts the incident number as a parameter, fetches the incident details and send it as JSON object back to client script.
Then in the client script, write on change client script on the incident number and call this SI. Based on the response, parse it and display them on top of the form using g_form.addInfoMessage.
You can also do with g_form.getReference, but best is to go with SI.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2022 12:01 PM
Q.
Create description field in child table, what ever description is mentioned in child record should be displayed as alert message in parent when you open a form .---------------
client script---------------
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('childp');
var a = g_form.getUniqueValue();
ga.addParam('akshat',a);
ga.addParam('sysparm_name', 'des');
ga.getXML(ak);
function ak(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer != "" && answer!=null){
alert(answer);
}}
script include -------
var childp = Class.create();
childp.prototype = Object.extendsObject(AbstractAjaxProcessor, {
des : function(){
var b = this.getParameter('akshat');
var gr = new GlideRecord("u_child");
gr.addQuery('u_parent',b);
gr.query();
if (gr.next()) {
var d= gr.getValue('u_description');
}
return d;
},
type: 'childp'
});
------------------------------------------------------------------------------------------------------------------
Q. When form is loading display “Username”, “current time and date” and “user manager name” is alert .
client script ----------------
function onLoad() {
//Type appropriate comment here, and begin script below
var b = new Date();
var m=g_scratchpad.manager;
var e= g_scratchpad.email;
alert(b+" "+ m+' '+e)
}
business rule---------display
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var a= gs.getUserID();
var b= new GlideRecord('sys_user');
b.addQuery('sys_id',a);
b.query();
if(b.next()){
g_scratchpad.manager=b.getDisplayValue('manager');
g_scratchpad.email=b.getDisplayValue('email');
}
})(current, previous);
--------------------------------------------------------------------------------------------------------------------
Q.
Create state field (open, onhold , close) in parent table , you should not be able to close parent record if child record associated with it have state is open .-------------
business rule-----------before update--------------------
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var a = current.u_state;
if(a=='3'){
var gr = new GlideRecord("u_child");
gr.addQuery("u_parent", current.sys_id);
gr.addQuery('u_state','1');
gr.query();
while (gr.next()) {
current.setAbortAction(true);
// current.setValue('')
}
}
})(current, previous);
-------------------------------------------------------------------------------------------------------------------
Q.
Create button in parent table “ create record” , if I click on that button it should create record in child table and created child record should visible in parent table related list.
uiAction
var gr = new GlideRecord("u_child");
gr.initilize();
gr.u_parent = current.sys_id;
gr.insert();
Create a button in parent “one click” , if I click the button one time then it should be hidden automatically .
uiaction
show insert only
Q.
Whenever you create record in “parent” table it should create record in child table and created child record should visible in parent table related list.
business--------after -insert update
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("u_child");
gr.initilize();
gr.u_parent = current.sys_id;
gr.insert();
})(current, previous);
-------------------------------------------------------------------------------------------------------
Q.
Create field “priority” with value 1,2,3. If priority is 1 then it should create record in child table and created child record should visible in parent table related list.-----
business rule--------after insert/update-----priority is 1 condition-----
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("u_child");
gr.initilize();
gr.u_parent = current.sys_id;
gr.insert();
})(current, previous);
--------------------------------------------------------------------------------------------------------------------
Acl
Q.Only person who created parent record will be able to edit parent table .
write---- read both
var a = current.sys_created_by;
var b = gs.getUserName();
if(a==b){
answer=true;
}else{
answer=false;
}
Q.
Create new field in parent table “assignment group” only group member will be able to edit parent table .
write---- read both
var a = current.u_assignment_group;
if(gs.getUser().isMemberOf(a)){
answer= true;
}
else{
answer= false;
}
Q
Create new field in parent table “assigned to” only assigned to person will be able to edit parent table .
write---- read both
var a = current.u_assigned_to;
if(a== gs.getUserID()){
answer=true;
}else{
answer=false;
}