how to populate company field in sc task using business rule servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2025 04:37 AM
Hi All,
Please suggest how to achieve the below requirement:
how to populate company field in sc task using business rule servicenow
I have tried below script but not works:
(function executeRule(current, previous /*null when async*/ ) {
// Get current record Requested For user
var requestedFor = current.requested_for;
// Get Requested For user details
var getUserCompany = new GlideRecord("sys_user");
getUserCompany.get(requestedFor);
// Store Requested For Comapnay
var userCompany = getUserCompany.company;
// Update RITM Company field
current.company = userCompany;
current.update();
// Update SCTASk Company field
var getCatalogTask = new GlideRecord("sc_task");
getCatalogTask.addQuery("request_item", current.sys_id);
getCatalogTask.query();
while (getCatalogTask.next()) {
getCatalogTask.company = userCompany;
getCatalogTask.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2025 08:36 AM - edited 04-13-2025 06:53 PM
Hi @ Ashok
May I know how you are managing the service requests?
Using workflow or flow designer??
If it's a flow designer, then you can achieve this within the flow. It's way easier than the business rule.
Write on before business rule on sc_task table.
// Fetch user company.
var user = new GlideRecord('sys_user');
user.get(current.request_item.requested_for);
var company _id = user.company;
current.company = company_id;//set company value in the script task record
Regards,
Siva

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2025 06:48 PM
@ Ashok First of all never use current.update() in a business rule, it can bring a lot of unwanted problems for you. Secondly you can achieve this using an onBefore insert/update business rule on sc_task table with following code.
current.company = current.request_item.request.requested_for.company+'';
You just need this single line to update the company field on your sc_task record.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-13-2025 08:53 PM
you can use before insert BR for this on sc_task with proper conditions and use Actions Tab and no scripting required
something like this
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader