Script Include return value

chaitanyakumar
Tera Expert

Hi,

I have requirement if any one of the approval request for change is approved then doesn't show UI Action on form. I have written Script Include and checking all the approval requests for change and if any of state is approved return false otherwise return true but it's always returning True even one of the approval request is approved

Script Include:

find_real_file.png

UI Action:

find_real_file.png

I am checking this return value by System Logs. Is there anything i am missing here?

Thanks,

Chaitanya

9 REPLIES 9

dvp
Mega Sage
Mega Sage

for your requirement you don't even need a script include.



Just in the condition put current.state == 'approved' and if you want this button to show only to CAB members then use either script include or role if there is one only to CAB members


scottyharris
Kilo Contributor

Hey, Hi , I have a similar sort of requirement, where I need to show Close UI action only to requester and Change Aprrovers, can you help me with the script include for this?

The SN Nerd
Giga Sage
Giga Sage

Assuming that you can't use dvp's suggestion, your code seems to have a few logical errors.


All you need to do is this:



checkApproval: function() {


var changeId = this.getParameter('sysparm_changeid'); //sys_id


var approverGr = new GlideAggregate('sysapproval_approver');


var numOfApproved = 0;


approverGr.addQuery('document_id',changeId);


approverGr.addQuery('source_table','change_request');


approverGr.addQuery('state','approved');


approverGr.addAggregate('COUNT');


approverGr.query();


if ( approverGr.next() ) {


  numOfApproved = approverGr.getAggregate('COUNT');


}


gs.print(numOfApproved);


return (numOfApproved >= 1)


}



GlideAggregate examples



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Abhinay Erra
Giga Sage

You should not be using client callable script include here. Condition field will use server side script. Post your script include here instead of a screenshot so that I can edit the code