How to only to check child table acl in script

EshikaAgrawal
ServiceNow Employee
ServiceNow Employee

Hi,

Below script worked but problem is it's returning child+parent level fields, is there any way to avoid parent level fields? basically dont want to run loop for parent table fields

(function process(request, response) {

    var result = {

        table: 'testtab',

        fieldsChecked: [],

        allReadable: true

    };

 

    var gr = new GlideRecord('test_tab');

    if (!gr.isValid()) {

        response.setStatus(400);

        return { error: 'Invalid table: testtab' };

    }

 

    gr.query();

    if (!gr.next()) {

        response.setStatus(404);

        return { error: 'No records found in testtab' };

    }

 

    //  Dynamically get all field names (including inherited)

    var fieldList = gr.getFields(); // Vector of GlideElements

    var fieldNames = [];

 

    for (var i = 0; i < fieldList.size(); i++) {

        var glideElement = fieldList.get(i);

        fieldNames.push(glideElement.getName());

    }

 

 

    function checkFieldReadAccess(gr, fieldNames) {

        var failedFields = [];

        for (var i = 0; i < fieldNames.length; i++) {

            var field = fieldNames[i];

            var element = gr.getElement(field);

            var canRead = element && element.canRead();

            result.fieldsChecked.push({

                field: field,

                canRead: canRead,

                element:element

            });

            if (!canRead) {

                failedFields.push(element);

            }

        }

        return failedFields.length === 0;

    }

 

    result.allReadable = checkFieldReadAccess(gr, fieldNames);

 

    response.setStatus(200);

    return result;

 

})(request, response);

 

 

Tried==> var fieldNames = gr.getED().getFieldNames();  but its not working

 

2. Also, like we have canRead() for checking read similarly do we have these checks for query_range or report_view or list_edit in script?

8 REPLIES 8

SANDEEP28
Mega Sage

@EshikaAgrawal Did you try my code ?

 

If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!

Hi @SANDEEP28 ,

It;s returning child fields but not all fields, I see, i have field called name, that's not returned

SANDEEP28
Mega Sage

@EshikaAgrawal what is your exact requirement ?? From your previous conversation, I can see you are trying to retrieve fields which are not inherited form extended table 

@SANDEEP28 

yes, i only want records present in child table, so for this purpose i created table having name and roll_no as field names so when i ran the script onlt roll_no filed is coming and not name.