FAFR script to populate drop down list of emailIds to notify for the requester.

FAFR script to populate drop down list of emailIds to notify for the requester.

Requirement:
Populate "Email Ids to Notify" field dropdown for requester login.

Steps to follow:
1.  Goto the required request template >> Field and form rules > On Form Load
2.  Paste the attached script content and save it with a name.  
  1. var fafrKey = "EMAILCC";
  2. var cs_value = $CS.getValue(fafrKey);

  3. $CS.referField(fafrKey, "users", {
  4.     multiple: true,
  5.     ajax: {
  6.         url: "api/v3/users",
  7.         data: function(params) {
  8.             var input_data = {
  9.                 "list_info": {
  10.                     "row_count": 100,
  11.                     "fields_required": ["email_id"],
  12.                     "search_fields": {
  13.                         "email_id": params
  14.                     }
  15.                 }
  16.             };
  17.             if (params === "") {
  18.                 delete input_data.list_info.search_fields;
  19.             }
  20.             return {
  21.                 "input_data": $CS.toJSONString(input_data)
  22.             };
  23.         },
  24.         results: function(res) {
  25.             var list = [];
  26.             var data = res.users;
  27.             for (var i = 0, len = data.length; i < len; i++) {
  28.                 if (data[i].email_id !== null) {
  29.                     list.push({
  30.                         id: data[i].email_id,
  31.                         text: data[i].email_id
  32.                     });
  33.                 }
  34.             }
  35.             return {
  36.                 results: list
  37.             };
  38.         }
  39.     },
  40.     formatSelection: function(data) {
  41.         return data.id;
  42.     }
  43. });

  44. if (cs_value !== "") {
  45.     var arr = cs_value.split(",");
  46.     var arr_length = arr.length;
  47.     var list = [];
  48.     for (var i = 0; i < arr_length; i++) {
  49.         list.push({
  50.             id: arr[i],
  51.             text: arr[i]
  52.         });
  53.     }
  54.     $CS.element(fafrKey).select2("data", list);
  55. } 
3.  Enable this rule for only requesters login.

With ESM (11000) release, requesters can be given access for GET and GET ALL users api operations to achieve certain requirements. This will be disabled by default and needs to be enabled by executing the below query in the database,

update globalconfig set paramvalue='true' where parameter = 'AllowUserAPIInRequesterLogin';

Refer to this article for the instructions to connect to the database.​

                    New to ADSelfService Plus?

                      • Related Articles

                      • How to populate requester details in request additional field

                        Requirement: Populate requester additional field information into request additional field. Usecase: Let us consider a scenario where certain employee details are imported from the Active Directory into User - Additional Fields. The business ...
                      • Script to Populate User Additional Field under Incident Template using FAFR

                        The script load the Requester Name under Incident Additional field ( As a pick list), by choosing the requester name under additional field the script populates the user additional field value. * Kindly create two additional fields under Admin -> ...
                      • How to populate user names in a request additional field

                        This sample script is to populate both technician and requester names in a request additional field Use Case: Populate all user name in a request additional field. Execution Steps:  1.  Create a new 'Single Line' additional field and add them in the ...
                      • Script to set fields from CSV using FAFR.

                        Works in 10604 Requirement: Load Data from CSV depending on the value selected in an additional field. Usecase: Assume there are 3 additional fields for a request template, namely, "Reference number", "Payment type and "Vendor". "Reference number" is ...
                      • Custom Module-Based Dependent Fields with FAFR

                        In the dynamic world of IT service management, form simplicity and accuracy play a major role in how smoothly requests are handled. However, many organizations face a recurring challenge—dependent field limitations within ServiceDesk Plus. Currently, ...