Concatenation of Name field of the user belonging to specific department without affecting users

ark257
Mega Contributor

I have written a business rule on sys_user table

 

before query

 

condition: Department.name=='XYZ'

 

var firstName = g_form.getValue('first_name');
var lastName = g_form.getValue('last_name');
var Name = firstName + ' ' + lastName;
g_form.setValue('Name', Name);

But the condition is returning null value when business rule is ran

1 REPLY 1

M Iftikhar
Mega Sage

Hi @ark257,

The issue you’re running into is because g_form is only available on the client side (forms, UI Policies, client scripts, etc.). A Business Rule runs on the server side, so g_form.getValue() will always return null there. 

If your goal is to set the name field on the sys_user table based on first_name and last_name, you should switch to a before insert/update Business Rule and use the current object instead of g_form.

For example:
 

// Business Rule on sys_user
// When: before insert OR before update
if (current.department.name == 'XYZ') {
var firstName = current.first_name.toString();
var lastName = current.last_name.toString();
current.name = firstName + ' ' + lastName;
}

   

A couple of things to keep in mind: 

  • current.<field> is the right way to access field values in server-side scripts. 
  • The name field on sys_user is normally system-controlled, so confirm it’s okay to override in your instance. 

Docs that might help: 

Thanks & Regards,   

Muhammad Iftikhar   

If my response helped, please mark it as the accepted solution so others can benefit as well.