- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:05 AM
Hi,
i try this script :
var gr = new GlideRecord('sys_user');
var count = 0;
gr.addQuery('company', '=', '');
gr.query();
while(gr.next())
{
gr.setWorkflow(false);
gr.company= 'CD68 - Département du Haut-Rhin';
gr.update();
count = count + 1;
}
gs.print(count);
Result i get, is in list view Company is displayed : ok
but if i go into the user form, the field is empty, and in fact with my filter on application menu (filter on company of the user have open incident), i see nothing
I think the value is not good but just the display is ok, what i need to change in my script to fix Company correctly on users
Best regards,
Cedric
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:25 AM
Hi,
thx with you're information i finnaly find the correct script :
var grcompany = new GlideRecord('core_company');
grcompany.addQuery('name', '=', 'CD68 - Département du Haut-Rhin');
grcompany.query();
if(grcompany.next())
{
gs.print(grcompany.sys_id);
var gr = new GlideRecord('sys_user');
var count = 0;
gr.addQuery('company', '=', 'CD68 - Département du Haut-Rhin');
gr.query();
while(gr.next())
{
gr.setWorkflow(false);
gr.company=grcompany.sys_id;
gr.update();
count = count + 1;
}
gs.print(count);
}
thanks for help,
Regards,
Cedric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:11 AM
Your script is setting the company, not the department. Company is a reference field on the user form so you need to either pass in a sys_id or use setDisplayValue().
The below script would work to set the value of a reference field but i think you need to confirm whether you're setting the department or the company.
var gr = new GlideRecord('sys_user');
var count = 0;
gr.addQuery('company', '=', '');
gr.query();
while(gr.next())
{
count++
gr.setWorkflow(false);
gr.company.setDisplayValue('CD68 - Département du Haut-Rhin');
gr.update();
}
gs.print(count);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:15 AM
Hi,
sorry for this mistake, in filter i use company of opened_by.
(ii edit my post) thanks a lot.
Regards,
Cedric
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:18 AM
OK so if you're trying to set the company that's fine, the script i've provided should work. As i said, with reference fields you need to either pass in a sys_id or use setDisplayValue()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2019 01:25 AM
Hi,
thx with you're information i finnaly find the correct script :
var grcompany = new GlideRecord('core_company');
grcompany.addQuery('name', '=', 'CD68 - Département du Haut-Rhin');
grcompany.query();
if(grcompany.next())
{
gs.print(grcompany.sys_id);
var gr = new GlideRecord('sys_user');
var count = 0;
gr.addQuery('company', '=', 'CD68 - Département du Haut-Rhin');
gr.query();
while(gr.next())
{
gr.setWorkflow(false);
gr.company=grcompany.sys_id;
gr.update();
count = count + 1;
}
gs.print(count);
}
thanks for help,
Regards,
Cedric