How to Autopopulate String type variable by using List type reference field values?

HARI KISHAN GVS
Mega Sage

Hi team,

As per my requirement i have to populate user email and department String type variables by using requested for variable which is list type.

HARIKISHANGVS_0-1695296405905.pngHARIKISHANGVS_1-1695296445253.png

for example, if i select three users Koepke, Lliona, Reid in Requested for field, Requested for Email Address  field should populate like koepke@email.com,lliona@email.com,reid@email.com 

i Know, we need to write a onchange client script and use a client callable script include to do it. But my scripting knowledge is limited.  

I would greatly be thankful for the sample script to acheive this.

Thanks in advance,

Hari Kishan.

1 ACCEPTED SOLUTION

Vengateshwaran
Mega Guru

Hi @HARI KISHAN GVS,

Refer to the screenshots below, 

Please mark the answer as correct and helpful, If I answered your query. It will be helpful for others who are looking for similar questions.

View solution in original post

2 REPLIES 2

Vengateshwaran
Mega Guru

Hi @HARI KISHAN GVS,

Refer to the screenshots below, 

Please mark the answer as correct and helpful, If I answered your query. It will be helpful for others who are looking for similar questions.

Revanth Karra
Tera Expert

Dear Hari Kishan GVS,

 

Hope you're doing great!

 

@HARI KISHAN GVS , here is the sample script. Give a shot!

 

 

// Client script
function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || newValue === '') {
    return;
  }

  // Get the requested for email addresses.
  var requestedForEmails = [];
  var requestedForRecords = gs.getUser().getRecordIDs(newValue);
  for (var i = 0; i < requestedForRecords.length; i++) {
    var requestedForRecord = gs.getUser().getRecord(requestedForRecords[i]);
    requestedForEmails.push(requestedForRecord.getValue('email'));
  }

  // Set the requested for email address field.
  gs.setValue('requested_for_email_address', requestedForEmails.join(','));
}

// Client callable script include
function getRequestedForEmailAddresses(requestedForUsers) {
  var requestedForEmails = [];
  for (var i = 0; i < requestedForUsers.length; i++) {
    var requestedForRecord = gs.getUser().getRecord(requestedForUsers[i]);
    requestedForEmails.push(requestedForRecord.getValue('email'));
  }

  return requestedForEmails.join(',');
}

 

 

To use this script, you will need to:

  1. Create a new client script and paste the first code snippet into the Script field.
  2. Create a new client callable script include and paste the second code snippet into the Script field.
  3. Attach the client script to the Requested for field on your form.
  4. Create a new string field on your form called Requested for Email Address and set the Display Type to Read Only.
  5. Add the Requested for Email Address field to the layout of your form.

Once you have done this, the Requested for Email Address field will be populated automatically when the user selects one or more users in the Requested for field.

 

Kindly, please mark my solution as Helpful/Correct, if applicable. If I could help you with your Query then, please hit the Thumb Icon and mark as Correct!!!

 

Thanks & Regards, 

Revanth. K

Product Test Automation Engineer