Facing issues with the below code where I am trying to populate Incident number from table inc

Sony Sharma
Tera Contributor

   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

Jaspal Singh
Mega Patron
Mega Patron

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);
}
}

inc and newInc are declared but not used anywhere

 

Sandeep Rajput
Tera Patron
Tera Patron

@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.

Chavan AP
Kilo Sage

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*****