Facing issues with the below code where I am trying to populate Incident number from table inc
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 10:37 PM
Facing issues with the below code where I am trying to populate Incident number from incident table:
function onLoad() {
//Type appropriate comment here, and begin script below
var inc=g_form.getActionName('create_ofi');
var newInc=g_form.getReference(inc);
g_form.setValue('incident', newInc.sys_id);
}
4 REPLIES 4

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2023 10:39 PM
Try below.
function onLoad() {
//Type appropriate comment here, and begin script below
var inc=g_form.getActionName('create_ofi');
var newInc=g_form.getReference('create_ofi',callbackis);
function callbackis(newInc)
{
alert('Incident is '+newInc.sys_id);
g_form.setValue('incident', newInc.sys_id);
}
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 01:45 AM
inc and newInc are declared but not used anywhere

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2023 04:21 AM
@Sony Sharma Please try the following script.
function onLoad() {
//Type appropriate comment here, and begin script below
g_form.getReference(inc,callback);
function callback(newInc){
g_form.setValue('incident', newInc.sys_id);
}
}
Hope this helps.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2023 04:25 PM
this code might help:
var inc = g_form.getActionName('create_ofi');
// Check if the incident action exists and has a valid reference
if (inc) {
var newInc = g_form.getReference(inc);
// Check if the newInc reference is not null
if (newInc) {
g_form.setValue('incident', newInc.sys_id);
} else {
// Handle the case where the reference is not valid or null
console.error('Error: Unable to get a valid reference for the incident.');
}
} else {
// Handle the case where the incident action is not found
console.error('Error: Incident action not found.');
}
Glad I could help! If this solved your issue, please mark it as ✅ Helpful and ✅ Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****