Ref qualifier for type Field name

Khanna Ji
Tera Guru

I have a field of type field name which is dependent on another type of type table. How can I show only those fields which are references to the user table only? 

7 REPLIES 7

Anil Lande
Kilo Patron

Hi,

You have to make it dependent on the field which stores table name (field of type Table Name). 

find_real_file.png

Once you select table in table field, Field Name field shows fields of that table in dropdown.

find_real_file.png

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Whatever you are showing is already done. My question is after this part. Field field as per your screenshot should only show Manager field since its referenced from user field.

I want the field type field to show only those fields which are referenced to sys_user field - like Manager, Assigned To, Managed By, Owned by etc. nothing else.

 

 

In that you need to use attributes 'fieldChoicesScript' to get selected fields as per your need.

find_real_file.png

 

Create a script include and pass name of script include to this attribute.

Your script include script would be like below:

var GetUserTableReferenceFields = Class.create();
GetUserTableReferenceFields.prototype = {
    initialize: function() {},
    process: function(tableName) {
		gs.info('Table Name '+tableName);
        var result = [];
		var ele = '';
        var gr = new GlideRecord('sys_dictionary');  
        gr.addQuery('internal_type', 'reference'); //apply query internal_type=reference^reference=sys_user
        gr.addQuery('reference', 'sys_user');
		gr.addQuery('name',tableName).addOrCondition('name','task');		
        gr.query();
        while (gr.next()) {
            ele = gr.element + '';
            result.push(ele);
        }
        return result;
    },

    type: 'GetUserTableReferenceFields'
};

 

Make sure to pass 'GetUserTableReferenceFields' to the attribute like below and make dependednt on table name type fields:

fieldChoicesScript=GetUserTableReferenceFields

 

Thanks,
Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Thanks for the answer, this was helpful.

I adjusted the process function so that it shows all reference fields from the table itself or its parent tables:

    process: function(tableName) {
        var referenceFieldNames = [];
        var tableHierarchy = new GlideTableHierarchy(tableName);

        var grDictionary = new GlideRecord('sys_dictionary');
        grDictionary.addQuery('internal_type', 'reference');
        grDictionary.addQuery('name', 'IN', tableHierarchy.getTables());
        grDictionary.query();
        while (grDictionary.next()) {
            referenceFieldNames.push(grDictionary.getValue('element'));
        }
        return referenceFieldNames;
    },