The CreatorCon Call for Content is officially open! Get started here.

How do I pass the sys_id from the UI action condition to a script include

phantom7
Giga Expert

Hello,

 

I would like to pass the sys_id of a change_request to a script include.

The background is that I ran out of room on the condition filter for my UI action that is on the change_request table. I was told that I can use a script include. So I did, but for some reason I can't pass the sys_id of the change request to from the UI action to the change_request. I have spent so much time trying to figure out what the issue is. Please help. Thanks in advance.

Here is the condition on my UI action:

!(new hasImpTask().hasImplementationTask(current.getUniqueValue()))

Bellow is the script include:

var hasImpTask = Class.create();
hasImpTask.prototype = {

initialize :function(){},

hasImplementationTask: function(sysid) {
var gr = new GlideRecord('change_task');
gr.addEncodedQuery('change_request=' + sysid);
gr.query();
while(gr.next()){
if(gr.getValue('change_task_type') == 'implementation'){
return true;
}else if(gr.getValue('state') != 3 && gr.getValue('state') != 4 && gr.getValue('change_task_type') != 'review'){
return true;
}
}
return false;
},
type :'hasImpTask'
};
2 REPLIES 2

nataliya_b
Tera Guru
Your script include checks for implementation task and return true, if task found, but ui condition has ! (Not), that means if no implementation task found. Is this correct logic?

Knight Rider
Mega Guru

Hi,

If you are using Out of the box UI Action  you have to first check  the sys_class_name == change_request

else

you can update below condition in your UI ACTION Condition

 

!hasImplementationTask(current.getUniqueValue())

script include:

NAME: hasImplementationTask

 

Client Callable : FALSE

// UPDATE YOUR SCRIPT INCLUDE WITH BELOW AND CHANGE  FUNCTION PARAMETER TO CURRENT


function    hasImplementationTask(current) {
var gr = new GlideRecord('change_task');
gr.addEncodedQuery('change_request=' + current.getUniqueValue());
gr.query();
while(gr.next()){
if(gr.getValue('change_task_type') == 'implementation'){
return true;
}else if(gr.getValue('state') != 3 && gr.getValue('state') != 4 && gr.getValue('change_task_type') != 'review'){
return true;
}
	else
	{
		return false;
	}
}
}

Thanks,

-Vinay.