For sc_task table- Query Business Rule is not working as expected

Udhayakumar_30
Tera Contributor

I have written a query BR for "sc_task" table-where in I have used this encoded query "requestISEMPTY^opened_by.countryNOT INUT,UKA^NQrequestISNOTEMPTY^request.requested_for.countryNOT INUT,UKA"  

 

The logic behind this : example--there are some sc_task without Request/RITM . I need to show the empty sc_task to all users which I restricted also. Below is the full code:

NQ" is not working as expected. Kindly please let me know how this can be achieved through encoded query? 

var user = gs.getUser().getCountry();

    // Restricted
    if (user == 'CE|| user == 'KP') {

    
            current.addEncodedQuery('requestISEMPTY^opened_by.countryNOT INUT,UKA^NQrequestISNOTEMPTY^request.requested_for.countryNOT INUT,UKA');
    }

 

2 REPLIES 2

G Ponsekar
Mega Guru

@Udhayakumar_30 ,

 

can you check this: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0564887

 

Also can you try like below:

(function executeRule(current, previous /*null when async*/) {
    var userCountry = gs.getUser().getCountry();
    // Assuming 'CE' and 'KP' are the two-letter codes for your restricted countries.
    var restrictedCountries = ['CE', 'KP'];

    // Check if the user is in a restricted country.
    if (restrictedCountries.indexOf(userCountry) > -1) {
        // Build the query to show tasks with an empty request OR tasks where the requestor's country is NOT UT or UKA.
        var encodedQuery = 'requestISEMPTY^ORrequest.requested_for.countryNOT INUT,UKA';

        // Add the encoded query to the current query.        
current.addEncodedQuery(encodedQuery); } })(current, previous);

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

 

Thanks, GP

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Udhayakumar_30 

there are issues when you use NQ in query business rule.

check the link shared by @G Ponsekar which explains the same.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader