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

Need to pull a value from the Opened For's HR Profile

Rylie Markle
Tera Contributor

I want to add a value from the Opened For's HR Profile to a tab on the case form. When I go to add fields, it only gives me access to the Subject Person's HR Profile. Is there a way I can make a field with this information? Or do I only have access to pull from the Opened For/By's User Profile?

 

RylieMarkle_0-1686343451373.pngRylieMarkle_1-1686343462395.png

 

19 REPLIES 19

Shaikh Mzhar
Tera Guru

Hi @Rylie Markle 

 

by default, the case form displays information from the Opened By's User Profile and not the Opened For's HR Profile. However, you can customize the form to add a field that displays information from the Opened For's HR Profile. Here's a general approach to achieve this:

  1. Identify the HR Profile field: Determine the specific HR Profile field on the User table that corresponds to the Opened For user. You'll need the field name to reference it in your customization.

  2. Create a new field on the case table: Navigate to the Case table's dictionary (e.g., sys_dictionary.list.do?sysparm_query=name%3Dincident). Create a new field that will hold the value from the Opened For's HR Profile. Choose an appropriate field type based on the HR Profile field you identified in step 1.

  3. Write a business rule or client script: Create a business rule or client script that runs on the Case table when a record is loaded. In the script, retrieve the value from the Opened For's HR Profile field and set it in the newly created field on the Case table.

Here's an example of a client script that retrieves the HR Profile value from the Opened For user and sets it in a field named opened_for_hr_profile on the Case table:

 

function onLoad() {
  var openedFor = g_form.getValue('opened_for'); // Assuming 'opened_for' is the reference field for Opened For user
  if (openedFor) {
    var openedForUser = new GlideRecord('sys_user');
    if (openedForUser.get(openedFor)) {
      var hrProfileValue = openedForUser.<hr_profile_field>; // Replace '<hr_profile_field>' with the actual HR Profile field name
      g_form.setValue('opened_for_hr_profile', hrProfileValue);
    }
  }
}

 

 

Please mark helpful

Mzhar

I feel like I'm really close, but it isn't working. Do you notice anything I need to change? I put a screenshot of my Client Script, my new field (u_donator_current_top_balance), and the existing field I'm trying to pull from the Opened For's HR Profile (u_top_available). 

 

 

RylieMarkle_0-1686576993166.png

 

RylieMarkle_1-1686577037123.png

 

RylieMarkle_2-1686577066622.png

 

Sorry, I forgot to include my script. 

function onLoad() {
    //Type appropriate comment here, and begin script below

    var openedFor = g_form.getValue('opened_for'); // Assuming 'opened_for' is the reference field for Opened For user
    if (openedFor) {
        var openedForUser = new GlideRecord('sys_user');
        if (openedForUser.get(openedFor)) {
            var hrProfileValue = openedForUser.u_top_available;
            g_form.setValue('u_donator_current_top_balance', hrProfileValue);
        }
    }
}

 

Hi @Rylie Markle 

 

Please use below corrected code

function onLoad() {
  
var openedFor = g_form.getReference('opened_for', doAlert); // doAlert is our callback function 
    function doAlert(openedFor) {
      
            var hrProfileValue = openedFor.u_top_available;
            g_form.setValue('u_donator_current_top_balance', hrProfileValue);
        }
    }

Hi @Manmohan K ,

I updated the code, but it's now returning 'undefined'.

RylieMarkle_0-1686581848360.png

 

RylieMarkle_1-1686581882264.png