# Livechat setDepartment not working

**URL:** <https://forums.rocket.chat/t/livechat-setdepartment-not-working/8726>\
**Category:** Community Support\
**Created:** [October 1, 2020, 1:12pm UTC](https://forums.rocket.chat/t/livechat-setdepartment-not-working/8726 "2020-10-01T13:12:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkraats](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mkraats](https://forums.rocket.chat/u/mkraats)\
**Post date:** [October 1, 2020, 1:12pm UTC](https://forums.rocket.chat/t/livechat-setdepartment-not-working/8726/1 "2020-10-01T13:12:49Z")

</div>

Hi,

I’m trying to use the widget API to set the department when a user enters the chat. The background is that I want to use the same RC instance for a number of teams who each deal with a different topic. I’m using RC 3.7.0, freshly installed.

I have tried the setdepartment method and the intialize method. The other settings, ie color and title are showing up so why isn’t department being set?

```
RocketChat(function() {
this.initialize({
    theme: {
        color: '#04436A',
        fontColor: '#FFFFFF',
        iconColor: '#1d74f5',
        title: "Welkom to test chat",
       offlineTitle: "Service is offline",
    },
    department: 'my department',
    language: 'nl',

```

});  
});

---

<div class="post-metadata">

**Author:** ![minix](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@minix](https://forums.rocket.chat/u/minix)\
**Post date:** [October 1, 2020, 4:39pm UTC](https://forums.rocket.chat/t/livechat-setdepartment-not-working/8726/2 "2020-10-01T16:39:08Z")

</div>

This work.

RocketChat(function() {  
this.setTheme({ color: ‘#47A3DA’, fontColor: ‘#FFFFFF’, title: ‘ACME: ask support’ });  
this.registerGuest({  
token: GA\_makeid(17),  
name: ‘\<%=session(“UserNick”)%\>’,  
department: ‘IT support’,  
customFields: [  
{key: ‘Sess\_ServerName’, value: ‘\<%=session(“ServerName”)%\>’, overwrite:true},  
{key: ‘Sess\_Start’, value: ‘\<%=session(“Start”)%\>’, overwrite:true},  
{key: ‘Sess\_UserIP’, value: ‘\<%=session(“UserIP”)%\>’, overwrite:true},  
{key: ‘Sess\_Username’, value: ‘\<%=session(“username”)%\>’, overwrite:true},  
{key: ‘Sess\_UserNick’, value: ‘\<%=session(“UserNick”)%\>’, overwrite:true},  
{key: ‘Sess\_UserEmail’, value: ‘\<%=session(“UserEmail”)%\>’, overwrite:true},  
{key: ‘Sess\_Dipartimento’, value: ‘Supporto Reparto IT’, overwrite:true},  
{key: ‘Sess\_Context’, value: ‘INTRANET’, overwrite:true},  
{key: ‘Sess\_Item’, value: ‘all’, overwrite:true},  
]  
});  
});  
function GA\_makeid(length) {  
var result = ‘’;  
var characters = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz’;  
var charactersLength = characters.length;  
for ( var i = 0; i \< length; i++ ) {  
result += characters.charAt(Math.floor(Math.random() \* charactersLength));  
}  
return result;  
}

---

<div class="post-metadata">

**Author:** ![mkraats](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@mkraats](https://forums.rocket.chat/u/mkraats)\
**Post date:** [October 2, 2020, 11:23am UTC](https://forums.rocket.chat/t/livechat-setdepartment-not-working/8726/3 "2020-10-02T11:23:09Z")

</div>

Thanks, this does work indeed! I had department outside of the registerguest function in which case it does not work.

---

<div class="post-metadata">

**Author:** ![waliddd](https://avatars.discourse-cdn.com/v4/letter/w/45deac/32.png) [@waliddd](https://forums.rocket.chat/u/waliddd)\
**Post date:** [November 7, 2020, 10:03pm UTC](https://forums.rocket.chat/t/livechat-setdepartment-not-working/8726/4 "2020-11-07T22:03:44Z")

</div>

RocketChat(function() {  
this.setTheme({ color: ‘#47A3DA’, fontColor: ‘#FFFFFF’, title: ‘ACME: ask support’ });  
this.registerGuest({  
token: GA\_makeid(17),  
name: ‘\<%=session(“UserNick”)%\>’,  
department: ‘IT support’,  
customFields: [  
{key: ‘Sess\_ServerName’, value: ‘\<%=session(“ServerName”)%\>’, overwrite:true},  
{key: ‘Sess\_Start’, value: ‘\<%=session(“Start”)%\>’, overwrite:true},  
{key: ‘Sess\_UserIP’, value: ‘\<%=session(“UserIP”)%\>’, overwrite:true},  
{key: ‘Sess\_Username’, value: ‘\<%=session(“username”)%\>’, overwrite:true},  
{key: ‘Sess\_UserNick’, value: ‘\<%=session(“UserNick”)%\>’, overwrite:true},  
{key: ‘Sess\_UserEmail’, value: ‘\<%=session(“UserEmail”)%\>’, overwrite:true},  
{key: ‘Sess\_Dipartimento’, value: ‘Supporto Reparto IT’, overwrite:true},  
{key: ‘Sess\_Context’, value: ‘INTRANET’, overwrite:true},  
{key: ‘Sess\_Item’, value: ‘all’, overwrite:true},  
]  
});  
});  
function GA\_makeid(length) {  
var result = ‘’;  
var characters = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz’;  
var charactersLength = characters.length;  
for ( var i = 0; i \< length; i++ ) {  
result += characters.charAt(Math.floor(Math.random() \* charactersLength));  
}  
return result;  
}
