how to auto populate the cost center field value from caller/user to incident form using the business rule

Naresh44
Giga Contributor

Hi all,

I tried auto populating the 'cost center' field value from users table,  using the getReference method in business rule for incident form, but it didn't worked at all.

Please help me in retrieving the value of the cost center field value in the incident form

 

1 ACCEPTED SOLUTION

Hi Naresh,

 

As suggested by Ankur above won't work in business rule as g_form.getReference() are client specific side options to be used.

Try using below business rule that runs After Insert on required table & make sure you have correct field name passed.

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

    // Add your code here
    current.location = current.caller_id.location;

    current.cost_center = current.caller_id.cost_center;

    current.state = current.caller_id.state;

    current.city = current.caller_id.city;

    current.country = current.caller_id.country;
	
	current.update();

})(current, previous);

View solution in original post

25 REPLIES 25

Hi Naresh,

 

Is this in your Demo instance? As strangely I could not find the user named in ABRAHAM LINCOLN in my PDI. Kindly check if the street, location, etc. is populated for the user on the User table.

For some callers only country field value is not autopopulating.

Can you check for those Users if you have it corrrectly populated in User table once.

Try adding all the fields on the form layout & give it a check if the values itself exist for required fields that you want to copy values from.

BTW, these posts might help when posting questions in the future:

TNT: Screenshots Help, but Code is Better

TNT: And Formatted Code is Even Better

Ashley Snyder1
Giga Guru

If you have a reference to the User record with Caller, why not just add the fields from the Caller(+) to the form, rather than creating redundant fields and attempting to script them. You'll want to make them read only on the form/list, if a user changes them on the Incident form, it will change them on the user record.

It's best practice to navigate users to the pop-up for the Caller reference field to view these fields, but if necessary to show them on the incident form the above method can be used.