How to avoid quering table twice

Munny1
Tera Expert

Hi ,

 

As per our requirement we have an field in incident table parent incident if parent incident field is filled then we have custom filed  set  as true for the parent incident .
whenever parent incident value changes in the child incident the custom field set as false for the parent incident . The new parent incident custom filed  set  as true.


Below script is working as expected but need to avoid two time gliderecording of table how to achieve the same logic

 var gr = new GlideRecord('incident');
    if (current.parent_incident) {
        gr.get('sys_id', current.parent_incident);
        gr.parent_incident_checkbox = true;
		gr.update();
    } 

	
		if (current.parent_incident.changes()){
		
		var gr1 = new GlideRecord('incident');
        gr1.get('sys_id', previous.parent_incident);
        gr1.parent_incident_checkbox = false; 
		gr1.update();
    }

 

 

2 REPLIES 2

Harsh_Deep
Giga Sage
Giga Sage

Hello @Munny1 

 

You can use this -

 var gr = new GlideRecord('incident');
	
if (current.parent_incident.changes()){
        var gr1 = new GlideRecord('incident');
        gr1.get('sys_id', previous.parent_incident);
        gr1.parent_incident_checkbox = false; 
	gr1.update();
    }
else if (current.parent_incident) {
        gr.get('sys_id', current.parent_incident);
        gr.parent_incident_checkbox = true;
	gr.update();
    } 

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

u also glide recorded incident table two times i need to avoid that. Even previously my script also working as expected