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

Display only the records created by the currently logged in user and also the records where caller

Abhishek Kathe
Mega Guru

Display only the records created by the currently logged-in user and also the records where the caller person should be currently logged in user

4 REPLIES 4

yaswanthi2
Giga Sage

Hi @Abhishek Kathe 

Try with before query Business Rule on your required table and in the script field of business rule try something like below.

(function executeRule(current, previous /*null when async*/ ) {

  current.addEncodedQuery('sys_created_by='+ gs.getUser().getName()+'^caller_id='+ gs.getUserID());

})(current, previous);

Kalyani Jangam1
Mega Sage

Hi @Abhishek Kathe 

By using before query rule, you can achieve this,

Condition exclude admin role

Screenshot 2023-11-20 at 1.55.08 PM.png

Please check and Mark Helpful and Correct if it really helps you.

Community Alums
Not applicable

@Abhishek Kathe ,

 

Create Before - Query Business rule with:

 

advance tab.PNG

current.addQuery('sys_created_by', gs.getUserName()).addOrCondition('caller_id', gs.getUserID());

 

Hop this helps!

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Abhishek Kathe ,
I trust you are doing great.
Please find the code as given below

// Script to fetch records created by or where the caller is the currently logged-in user
(function() {
    var currentUser = gs.getUserID(); // Get the sys_id of the current user
    var gr = new GlideRecord('incident'); // Replace 'incident' with your target table

    // Add OR condition: Created by current user OR Caller is current user
    gr.addQuery('sys_created_by', currentUser);
    gr.addOrCondition('caller_id', currentUser);

    gr.query(); // Execute the query

    while (gr.next()) {
        // Process your records here
        // Example: gs.info(gr.number); // Log the incident number
    }
})();

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi