Auto-populate the assigned to field within the Hardware New record with a business rule

BenFan
Tera Expert

Hi,

I am trying to auto-populate the 'Assigned to' field in the Hardware New record with the user from the 'Requested for' field in the Requested Item, after the RITM number is populated in a custom field called 'RITM Number' in the Hardware New record.


I tried to auto-populate the 'Assigned to' field with a business rule I created, but whenever I add an RITM number to my custom field in the Hardware New record, the 'Assigned to' field remains empty.

 

My steps:
1. Accessed the business rules under system definition.

 

Created a business rule new record:
1. Advanced = checked

 

When to run:
1. When = before.
2. Update = checked.

 

Advanced:
1. I created a custom script.

 

See Assigned to1 and Assigned to2.

20 REPLIES 20

Okay, I checked the Insert box and unchecked the update box, and got the same result.Assigned to3.pngAssigned to2.pngAssigned to1.png

The more correct Condition on insert would be

current.assigned_to.nil() && !current.u_ritm_number.nil()

but let's remove that for now just to get this running.  Just to confirm understanding, the BR does not actually run until the record is created, so the Submit button is clicked in this scenario, so you should see the Assigned to populated after you click Submit.  If it's still not working with the Condition removed, let's add some logging to the script to find out what's going on:

(function executeRule(current, previous /*null when async*/) {

    gs.addInfoMessage('Assigned to is ' + current.assigned_to + ' RITM number is ' + current.u_ritm_number.number + ' RITM Request for is ' + current.u_ritm_number.requested_for.name);
    current.assigned_to = current.u_ritm_number.requested_for;

})(current, previous);

This should show at the top of the new record after it is created.  Please send a screenshot of the new hardware record form with this message.

 

Okay, let me see.

Looks like this worked, but as you said, the script can only auto-populate after you create the hardware record, then the user on the 'Requested for' field will appear to be 'Assigned to' field under the CMDB CI list. Assigned to3.pngAssigned to2.pngAssigned to1.png

 

If you want to see the Assigned to populate on the form right after you populate the RITM field, instead of the Business Rule you'll need an onChange Client Script on the alm_hardware table when RITM Number changes:

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

    // Populate Assigned to with Requested for of RITM when RITM changes
    g_form.getReference('u_ritm_number', setUser);
}

function setUser (ritm) {
    g_form.setValue('assigned_to', ritm.requested_for);
}