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

need change the REQUESTED FOR field filter conditions based on custom field values in SR form

Purushotham Ga2
Tera Contributor

Hi Experts,

In on-change/onload  catalog client script-

need change the REQUESTED FOR field filter conditions based on custom field values in SR form like if we select custom field ( user type).

 

Here we have 2 custom fields like User type and Requested for

User type have 2 options like employee and non employee

If we select employee then in Requestedvfor field should contain @employee.com related users only

if we select non employee then in requested for field should filter/contains @nonemployee.com. related users only.

 please assist me on this

4 REPLIES 4

Sainath N
Mega Sage

@Purushotham Ga2 : This cannot be implemented via client scripts and can be achieved via reference qualifiers. With the simple if-else condition in the reference qualifier, you will be able to achieve the requirement.

 

Below is the sample code and the screenshot. In my use case, based on the choice value, I am showing users whose email contains "example.com" and does not contain "example.com.". Replace with your exact conditions and give a try.

 

 

 

javascript: if(current.u_choice_field_1==3) 'emailLIKEexample.com'; else 'emailNOT LIKEexample.com';

 

sainathnekkanti_0-1703630347883.png

 

Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.

@Purushotham Ga2Did my response address your question, or is there anything else I can help you with?

 

Please mark this as correct answer and helpful if it resolved. Thanks!

Pradnyesh
Kilo Sage

Hello @Purushotham Ga2 

  1. Create one script include.
    var Filter_User = Class.create();
    Filter_User.prototype = {
        initialize: function() {
        },

        filterUser: function(user_type) {
     
            var user = '';
            var gr_user = new GlideRecord('sys_user');
            if(user_type == 'employee'){
                gr_user.addEncodedQuery('emailLIKE@employee.com');
                gr_user.query();
                while(gr_user.next()){
                    user = user + ',' + gr_user.sys_id;
                }
            }
            else if(user_type == 'nonemployee'){
                gr_user.addEncodedQuery('emailLIKE@nonemployee.com');
                gr_user.query();
                while(gr_user.next()){
                    user = user + ',' + gr_user.sys_id;
                }
            }
            return 'sys_idIN' + user.toString();

        },

        type: 'Filter_User'
    };
     
    2. Add below line in reference qualifier of requested for :
    javascript: new Filter_User().filterUser(current.u_user_type);

 

 

 

Please mark this response as correct or helpful if it assisted you with your question.

 

Regards,
Pradnyesh Dhapare

Tai Vu
Kilo Patron
Kilo Patron

Hi @Purushotham Ga2 

If your Requested for variable is in Reference type, you can set the Reference Qualifier in the Requested for variable.

Sample below.

(current.variables.user_type.toString() === 'employee') ? 'active=true^emailLIKE@employee.com' :  (current.variables.user_type.toString() === 'non_employee') ? 'active=true^emailLIKE@nonemployee.com' : 'sys_id=-1';

 

Cheers,

Tai Vu