- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 10:42 AM
The cost Center is populating and getting cleared immediately. Again populating only on selecting another field.
client script:
var userDetailsUtil = Class.create();
userDetailsUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEmployeeDetails: function() {
var userName = this.getParameter('sysparm_user');
var user = new GlideRecord('sys_user');
var result = { //Create an object to store the User data
name: "",
cc: "",
};
if (user.get(userName)) {
result.name = user.name.toString(); // toString is different from getDisplayValue
result.cc = user.cost_center.toString(); // toString is different from getDisplayValue
}
return JSON.stringify(result);
},
type: 'userDetailsUtil'
});
cost center populated and got cleared off:
cost center is populating only once the cursor moves to another field:
Can anyone help me to populate cost center.
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 11:31 AM
Hi Shidhi,
If you are seeing the cost center being populated and then disappearing, you are probably dealing with a case of dueling client scripts. I would suggest that you check through all your client scripts for others that touch the cost center field. It is possible to order the client scripts (you may need to add that existing field to the client script form) in case you have two On Loads that touch cost center to make sure that the one in question runs last. Please keep in mind that On Change scripts also run as part of loading a record.
:{)
Helpful and Correct tags are appreciated and help others to find information faster
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 11:31 AM
Hi Shidhi,
If you are seeing the cost center being populated and then disappearing, you are probably dealing with a case of dueling client scripts. I would suggest that you check through all your client scripts for others that touch the cost center field. It is possible to order the client scripts (you may need to add that existing field to the client script form) in case you have two On Loads that touch cost center to make sure that the one in question runs last. Please keep in mind that On Change scripts also run as part of loading a record.
:{)
Helpful and Correct tags are appreciated and help others to find information faster

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 11:59 AM
@Shidhi Check if there is any onChange script defined on the cost center table which is clearing the value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 01:03 PM - edited 05-21-2024 01:03 PM
Hi @Shidhi ,
As you are using onLoad() script. It means "Requester For" also pre populated as logged in User.
You can utilize the auto-populate feature for cost center becuase "Requested For" is reference type and User record has the cost center as reference field.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution