Service Portal snRecordPicker directive advanced reference qualifier

Katie A
Mega Guru

Hello,

I am using the 'sn-record-picker' directive in the Service Portal. I have it working with a basic query active=true.

<sn-record-picker table="'sys_user'" value-field="'sys_id'" display-fields="'email'" search-fields="'name,email'" page-size="100" default-query="'active=true'"></sn-record-picker>

I want a much more advanced query to pull the results, that is not possible to achieve with simple conditions. I already have a script include class that I am using for this purpose in an Advanced Reference Qualifier in the standard ui.

Is it possible to utilize script include class to populate the results (just like the Advanced Reference Qualifier in the standard ui)?

I would imagine there must be a way to pass in a script include method into the default-query attribute?

<sn-record-picker table="'sys_user'" value-field="'sys_id'" display-fields="'email'" search-fields="'name,email'" page-size="100" default-query="'advancedRefQual()'"></sn-record-picker>

10 REPLIES 10

Jon Barnes
Kilo Sage

it should work the same, just put the "javascript" in front of your function.

default-query="'javascript:advancedRefQual()'"

Thank you! 

I gave that a try but it does not seem to be working. As a test, the reference qualifier is just returning an encoded query with a hard-coded comma separated string of sys_ids.

The gs.log statement does not appear in the log... so the Script Include does not even seem to be running at all.

HTML

<sn-record-picker id="loaner_item" field="loaner_item" table="'cmdb_ci'" value-field="'sys_id'" display-fields="'short_description'" search-fields="'name,short_description'" page-size="100" default-query="'javascript:LNRRefQualSP()'" placeholder="Select Loaner Inventory Item"></sn-record-picker>

Script Include

find_real_file.png

In order to solve this issue I ended up just calling the Script Include from the Server script and populating the data object with the encoded query.

<!-- HTML -->
<sn-record-picker id="loaner_item" field="loaner_item" table="'cmdb_ci'" value-field="'sys_id'" display-fields="'short_description'" search-fields="'name,short_description'" page-size="100" default-query="c.data.loaner_item_query" placeholder="Select Loaner Inventory Item"></sn-record-picker>
//Server script
// Initialize Loaner Utilities script include class
var lu = new LNRUtils();

// Populate Computer Information cmdb_ci Loaner Item
data.loaner_item_query += lu.availableCis(item_type, pickup_location, pickup_date, return_date, peripheral_type);

SIMTEC
Kilo Contributor

Did this work for you? I am not able to run my script includes, which are working fine in for example catalog variables reference qualifiers.

Neither

- 'javascript:ScriptIncludes.MyFunction()'

does work inside default-query=" ", nor

- 'javascript:new global.ScriptIncludes.MyFunction()'

or other variations of that. No errors are shown, it just shows the whole table records.

 

Has anybody experience with getting script-includes to run in this sn-record-picker directive?

Thanks..