How to call a script include and return the result to a catalog variable

nakamura323
Kilo Guru

Hello.
I would like to call a script include in the reference modifier of a catalog variable.
Here, I would like to select the company and department to which I belong, and then narrow down the groups I want to browse by "name".

Since the table has values ​​such as BK and FG, it is assumed that only those containing the strings BK and FG will be queried.

Currently I am writing the script with only company variables.


This is a screenshot.

Select company from the Question Choice table
スクリーンショット 2024-03-20 220706.png

Question Choice table

スクリーンショット 2024-03-20 223534.png

 

Call script include.

"variables.---_test_employee_company" is the company catalog variable

スクリーンショット 2024-03-20 220551.png

 

script include; Query the sys_user_group table for names containing the string of the received argument.

スクリーンショット 2024-03-20 220505.png

 

Group selection (no company selected)

スクリーンショット 2024-03-20 224241.png

 

Group selection (select company)

スクリーンショット 2024-03-20 224300.png

 

In this case, why don't I see anything with the string BK in its name?

thank you.

 

1 ACCEPTED SOLUTION

nakamura323
Kilo Guru

Problem solved.

The cause was that the company selection type was set to reference.
It worked by changing the type to Select Box.

For more information, please visit the URL below.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0749932

https://note.com/rhayahi/n/n14c260f7209f#60a3818c-bc3e-45a5-a09a-e4745da55675
thank you.

 

View solution in original post

12 REPLIES 12

Brad Bowman
Kilo Patron
Kilo Patron

Check your initialization of the Script Include - just because your script editor is not formatting it exactly like what I am used to seeing:

BradBowman_0-1710954278824.png

 

Is your 'Group selection' variable a reference on sys_user_group?  If you manually filter a list view of the Groups table on active = true and name contains BK, how many group records do you see?  You can add some gs.addInfoMessage lines (or gs.info if that doesn't work in this case) to the Script Include to make sure it is running (not another SI with the same name) and confirm the value of the argument passed in from the reference qualifier, as well as if the GlideRecord returns any results.

 

The only other thing I can think of is to try a different array name - maybe 'list' is a reserved word?

thank you for your reply.

Is your 'Group selection' variable a reference on sys_user_group?

> Yes.

 

how many group records do you see?

> 156.

 

add some gs.addInfoMessage lines

> I added gs.info to the script includes, but it didn't print to the application log.

 

The only other thing I can think of is to try a different array name - maybe 'list' is a reserved word?

>I'll try a different array name as well.

I don't think "list" is a reserved word.

Thank you.

Basheer
Mega Sage

Hi @nakamura323 

I can think of giving the api name instead of just name in your reference qualifier. 

you have given it as new u_mids_test_id instead try the api name(you can see below the name field in script include) 

 

Please hit like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.

Cheers,
Mohammed Basheer Ahmed.

Harish KM
Kilo Patron
Kilo Patron

Hi @nakamura323 after your function add this line

gs.info("SI called==>"+comNam); // check whether your script include is called and the value you passed from reference qual prints in logs? then the next steps can be debugged

I would also advise make it a server side script include rather than client callable.

Regards
Harish