Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Saved View cannot be selected by the user

Lucky1
Tera Guru

Hello all,

 

We have created a mapping of business applications and once all done, we will save the view, and that saved views ill be stored in Saved Views table (ngbsm_view).

So, as an admin, I am designing the mapping and saved the view with a version. And using some script, I am creating one record to the business owner.

But when I impersonate the business owner and checks it, I am getting any option to select the saved view.

Lucky1_0-1756110197620.png

 

So, can someone tell me what all permissions should I provide the business owner to apply the saved view.?

Note: The business owner is able to see the record in Dependency Views table.

 

 

Regards,

Lucky

 
5 REPLIES 5

Lucky1
Tera Guru

Hello GlideFather,

 

One more thing is, I have just observed like, when I manually open the record, and change the user there and then do Insert & Stay, then the user is getting the popup to select the view and he is selecting.

But from the below script, when I run, the record is getting created but the popup itself is not showing up to select the saved view.

// Get all unique configuration items from ngbsm_view
var ciList = {};
var gr = new GlideRecord('ngbsm_view');
gr.addEncodedQuery('configuration_item=e294778783ba2210e958cd19feaad317');
//gr.orderBy('configuration_item');
gr.query();
while (gr.next()) {
    ciList[gr.configuration_item.toString()] = true;
}

// Loop through each CI
for (var ciSysId in ciList) {
    // Find the highest version record for this CI
    var grMax = new GlideRecord('ngbsm_view');
    grMax.addQuery('configuration_item', ciSysId);
    grMax.orderByDesc('version');
    grMax.setLimit(1);
    grMax.query();
    if (!grMax.next()) {
        continue;
    }

    var highestVersion = grMax.version;
    var businessOwner = grMax.configuration_item.owned_by.toString(); // Directly from reference field

    // Skip if Business Owner is empty
    if (gs.nil(businessOwner)) {
        gs.print("Skipping CI: " + ciSysId + " because Business Owner is empty");
        continue;
    }

    // Check if record already exists for this Business Owner with highest version
    var existing = new GlideRecord('ngbsm_view');
    existing.addQuery('configuration_item', ciSysId);
    existing.addQuery('user', businessOwner);
    existing.addQuery('version', highestVersion);
    existing.setLimit(1);
    existing.query();
    if (!existing.next()) {
        // Insert new record
        var grInsert = new GlideRecord('ngbsm_view');
        grInsert.initialize();
        grInsert.configuration_item = ciSysId;
        grInsert.version = highestVersion;
        grInsert.user = businessOwner;
        grInsert.insert();
        gs.print("Inserted new record for CI: " + ciSysId + " with highest version: " + highestVersion);
    } else {
        gs.print("Record already exists for CI: " + ciSysId + " with highest version: " + highestVersion + " and Business Owner: " + businessOwner);
    }

    // Delete all other versions for the same CI & Business Owner
    var grDelete = new GlideRecord('ngbsm_view');
    grDelete.addQuery('configuration_item', ciSysId);
    grDelete.addQuery('user', businessOwner);
    grDelete.addQuery('version', '!=', highestVersion);
    grDelete.query();
    while (grDelete.next()) {
        gs.print("Deleting record version: " + grDelete.version + " for CI: " + ciSysId);
        grDelete.deleteRecord();
    }
}

Can you help me?

 

 

 

Regards,

Lucky