- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2015 07:07 AM
A global business rules runs with the condition
Condition:Requested_For.hasRole('HBS_Cluster')==false
Script:
function getcompany(){
var company = [];
var user=current.Requested_For;
var gr = new GlideRecord('sys_user');
gr.addQuery(sys_id,user);
gr.query();
while(gr.next())
{
var country=gr.company;
}
var gr = new GlideRecord('hbs_o2c_companies');
gr.addQuery(u_country_name,country);
gr.query();
while(gr.next())
{
company.push(gr.sys_id.toString());
}
var company_string = company.join(',');
gs.log('company string is ' + company_string);
return 'sys_idIN' + company_string;
}
Not working ,,
Also suggest if there are other ways of doing it
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2015 08:07 AM
I would not do this as a global business rule, but as a default value on the variable. You could just use javascript:gs.getUser().getCompanyID(); in the default value to prepopulate a variable with the user's company id or javascript:gs.getUser().getCompanyRecord().fieldname; to get a field from the company record.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2015 08:07 AM
I would not do this as a global business rule, but as a default value on the variable. You could just use javascript:gs.getUser().getCompanyID(); in the default value to prepopulate a variable with the user's company id or javascript:gs.getUser().getCompanyRecord().fieldname; to get a field from the company record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2015 08:12 AM
You can use Catalog Client script to populate the Company Code.
I see problem with your addQuery. First parameter should be string:
gr.addQuery(sys_id,user); should be gr.addQuery('sys_id',user);
gr.addQuery(u_country_name,country); should be gr.addQuery('u_country_name',country);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2015 08:19 AM
I would go with what Brad has suggested. Ideally that should work.
If not, then configure a display business rule on your catalog item table by which you can get the company of the logged in user. Pass that value to scratchpad object variable which you can then use in catalog client script to set the value.
There are many errors in your code, along with what Saritha has suggested
Global rules should be avoided. You will configure those only if you want Rule to run on all tables.
Condtion : Requested_For.hasRole('HBS_Cluster')==false , it should have been current.requested_for.hasRole('hbs_cluster')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2015 02:22 AM
Wrote a Script Include Instead of business rule
With the help of these functions: gs.getUser().getCompanyRecord()
This works
Thanks