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);
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?