Category: Scenario-Based Questions PART 37
Updated on: August 12, 2025  |  0

Scenario-Based Questions PART 37

🎓 Scenario-Based Question

 

📋 Use Case: Auto-Populate Manager & Country from ‘Request For’ Field

A Catalog item has a Variable Set named Requester Info with 3 variables:

  • 🧑‍💼 Request For [Reference]
  • 👔 Requester Manager [Reference]
  • 🌍 Country [Single Line Text]

Goal: When a user is selected in Request For, auto-fill the user’s manager name in Requester Manager and the user’s country in Country.

1️⃣ Script Include: GroupManager

var GroupManager = Class.create();
GroupManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {

  getUserInfo: function() {
    var usr = this.getParameter('sysparm_user');
    var gr = new GlideRecord('sys_user');
    if (gr.get(usr)) {
      return gr.manager + "," + gr.location.country;
    }
    return '';
  },

  type: 'GroupManager'
});
  

2️⃣ Catalog Client Script

  • Name: Request For Information
  • Applies to: Variable Set
  • UI Type: All
  • Type: onChange
  • Variable Set: Requester Info
  • Variable Name: request_for
function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue == '') {
    return;
  }

  var ga = new GlideAjax('GroupManager');
  ga.addParam('sysparm_name', 'getUserInfo');
  ga.addParam('sysparm_user', newValue);
  ga.getXMLAnswer(_callback);

  function _callback(answer) {
    var answerArray = answer.split(',');
    g_form.setValue('requester_manager', answerArray[0]);
    g_form.setValue('country', answerArray[1]);
  }
}
  

3️⃣ Final Steps

  1. Save both the Script Include and the Catalog Client Script.
  2. Navigate to the Service Portal and test selecting a user in the Request For field.
  3. Verify that Requester Manager and Country fields are automatically populated.

✔️ Auto-population improves user experience and reduces manual errors!

Comments

No comments yet.


Log in to post a comment