# ログインユーザーのグループ名を取得し、画面項目の内容の比較について

**URL:** <https://community.cybozu.dev/t/topic/1138>\
**Category:** kintone 開発相談\
**Created:** [2022 年 11 月 10 日午前 11:38 UTC](https://community.cybozu.dev/t/topic/1138 "2022-11-10T11:38:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account2904](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@Legacy\_Account2904](https://community.cybozu.dev/u/Legacy_Account2904)\
**Post date:** [2022 年 11 月 10 日午前 11:38 UTC](https://community.cybozu.dev/t/topic/1138/1 "2022-11-10T11:38:41Z")

</div>

**背景・実現したいこと**

&nbsp;ログインユーザーのグループ名を取得し、画面項目の内容と比較をしたい。

&nbsp;エラーはありませんが、kintone.api(‘/v1/user/groups’,‘GET’,{

からいきなり、return event;へ飛んでしまいます。

code:user.codeは正しく取得出来ております。

何が原因なのかわからず困っております。

どなたかご教示お願い致します。

**エラー情報** （開発者ツールのコンソール）

&nbsp;エラーはありません。

**利用したソースコード**

(function () {

&nbsp; &nbsp; “use strict”;

&nbsp; &nbsp; var events = [‘app.record.detail.process.proceed’];

&nbsp; &nbsp; //レコード詳細表示のイベントハンドラー  
&nbsp; &nbsp; kintone.events.on(events, function(event){

&nbsp; &nbsp; if(event.action.value == ‘申請’ || event.action.value == ‘再申請’){  
&nbsp; &nbsp; &nbsp; &nbsp; var user\_group,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; group\_ary\_count,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user\_group\_ary = [],  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user = kintone.getLoginUser(),  
&nbsp; &nbsp; &nbsp; &nbsp; record = event.record,  
&nbsp; &nbsp; &nbsp; &nbsp; okflg = false,  
&nbsp; &nbsp; &nbsp; &nbsp; target\_ary = [];

&nbsp; &nbsp; &nbsp; &nbsp; /\*–ユーザーの所属グループのコードを表示する ※複数件ある場合–\*/  
&nbsp; &nbsp; &nbsp; &nbsp; kintone.api(‘/v1/user/groups’,‘GET’,{  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; code:user.code  
&nbsp; &nbsp; &nbsp; &nbsp; },function(resp){  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //所属グループの数を数える  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; group\_ary\_count = resp.groups.length;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //所属グループの中に特定のグループがあるかの場合分け  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(var i = 0; i \< group\_ary\_count; i++){  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user\_group = resp.groups[i].code;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user\_group\_ary.push(user\_group);  
&nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(var j = 0; j \< record[‘申請者’].value.length; j++){ &nbsp; &nbsp; &nbsp; &nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (user\_group\_ary.includes(record[‘申請者’].value[j].name)) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; okflg = true;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; target\_ary.push(record[‘申請者’].value[j].name);  
&nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(okflg == false) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.error = “申請者対象者ではありません!【申請対象者】”+target\_ary.join(‘’);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp;

&nbsp; &nbsp; }

&nbsp; &nbsp; &nbsp; &nbsp; return event;

&nbsp; &nbsp; });

})();

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1377](https://avatars.discourse-cdn.com/v4/letter/l/e495f1/32.png) [@Legacy\_Account1377](https://community.cybozu.dev/u/Legacy_Account1377)\
**Post date:** [2022 年 11 月 11 日午前 5:14 UTC](https://community.cybozu.dev/t/topic/1138/2 "2022-11-11T05:14:26Z")

</div>

HAYASHIDA さん

event.action.value == '申請’の「申請」はアクションですか？

もしかして「申請する」アクションを実行した後のステータスですか？

ステータスだと実行されないです。

こちらの[コメント](https://community.cybozu.dev/hc/ja/community/posts/202126090)は同じようなことをやっているので、参考になればと思います。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2904](https://avatars.discourse-cdn.com/v4/letter/l/4bbf92/32.png) [@Legacy\_Account2904](https://community.cybozu.dev/u/Legacy_Account2904)\
**Post date:** [2022 年 11 月 14 日午前 3:37 UTC](https://community.cybozu.dev/t/topic/1138/3 "2022-11-14T03:37:13Z")

</div>

akikaさん

返信が遅くなり申し訳ありません。

コメントありがとうございます。

event.action.value == '申請’の「申請」はアクションボタン名になります。

頂いたリンクを拝見させて頂きます。

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/cybozu/original/1X/d5c841c3c5a6cb66eed514001c1b45147c9e1f4f.png) [@system](https://community.cybozu.dev/u/system)\
**Post date:** [2024 年 6 月 1 日午前 1:54 UTC](https://community.cybozu.dev/t/topic/1138/4 "2024-06-01T01:54:21Z")

</div>

このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。
