- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 02:58 PM
Hi All,
On Our demand management, while creating the demands we populate the Business unit(u_business_unit) with the Department on the User record based on the submitted by field on the demand. Recently we have removed all the departments from our environment within snow and imported a new list of departments, which unfortunately removed the Business unit from Demands.
Is there a way to populate the Business unit field with the department of the Submitted by user record for the demands where Business unit field is empty?
Somekind of background script or fix script
Please help me with some sample script.
Thanks,
Sd
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 03:31 PM
Hello,
Here is an sample script that will hopefully help.
//call function
updateBusinessUnit();
function updateBusinessUnit() {
//query records where business_unit is empty
var dem = new GlideRecord('demands');//demand table
dem.addQuery('u_business_unit', '');
dem.query();
//Iterate through records and set the business_unit field
while(dem.next()) {
dem.u_business_unit = dem.submitted_by.department;
dem.update();
}
}
Cheers,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 03:16 PM
Yes. You can try below script
var ta = new GlideRecord('demand table name'); //replace with your demand table name
ta.addNullQuery('u_business_unit');
ta.query();
while (ta.next())
{
ta.u_business_unit= ta.submittedUser.department; //replace with you user and department field
ta.update();
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 03:31 PM
Hello,
Here is an sample script that will hopefully help.
//call function
updateBusinessUnit();
function updateBusinessUnit() {
//query records where business_unit is empty
var dem = new GlideRecord('demands');//demand table
dem.addQuery('u_business_unit', '');
dem.query();
//Iterate through records and set the business_unit field
while(dem.next()) {
dem.u_business_unit = dem.submitted_by.department;
dem.update();
}
}
Cheers,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-03-2017 01:29 AM
Hi snow123,
//Script background
var dmn = new GlideRecord('dmn_demand');//demand table
dmn.addQuery('u_business_unit', '');
dmn.query();
//Iterate through records and set the business_unit field
while(dmn.next()) {
//Assign department from User as a Business Unit for demand form
dmn.u_business_unit = dmn.submitted_by.department;
dmn.update();
}
I hope this helps 🙂
- Gopal Dutt Harbola
PS: Hit like, Helpful or Correct depending on the impact of the response