UI Action script is unable to read the sys_id of incident

Ketan Pandey
Tera Expert

I have created a UI Action on incident table .in UI Action Script i have written the below

 

 

var incident_sysid=g_form.getValue('sys_id');

alert(incident_sysid);

it returning null value

7 REPLIES 7

Hi @Ketan Pandey ,

you need to use the getReference Function, but as you need to query data from Backend this method should be used asynchronous by using a callback function.

 

 

 

g_form.getReference('caller_id', doAlert); // instead of caller_id use name of field for which you want to have the record. doAlert is our callback function

 
function doAlert(caller) { // reference is passed into callback as first arguments - type is GlideRecord
   if (caller.getValue('vip') == 'true') {
      alert('Caller is a VIP!');
   }
}

 

 

 

Greets
Daniel

Please mark reply as Helpful/Correct, if applicable. Thanks!

@Ketan Pandey 

 

if you want to do it for the sys_id of the incident self, you can also use GlideRecord asynchronous, but check if this is really needed or maybe a Before Query Business Rule with g_scratchpad can provide the information you need. There are for sure better ways - but for that we need more information, what you want to achieve.

 

 

function onClick() {
    var now_GR = new GlideRecord('incident');
    now_GR.addQuery('sys_id', g_form.getUniqueValue());
    now_GR.query(response);

    function response(result) {
        if(result.next()) {
             alert(result.getValue('number'));
        }
    }
}

 

Greets
Daniel

Please mark reply as Helpful/Correct, if applicable. Thanks!

Hi @Ketan Pandey ,

Now here suppose caller field is reference and I want it's display value then I can use code as below : 

function doSubmit(){
var incident_sysid=g_form.getUniqueValue();
var callerDetails= g_form.getDisplayBox('caller_id').value;

alert(callerDetails);
}

Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy