Cross Scope Issue

vidhya_mouli
Giga Sage

I have a Widget Server Script

(function() {
    data.accounts = [];
    data.attachments = []; // To store attachments
    var userSysId = gs.getUserID();
    
    // --- Step 1: Find customer_contact for the logged-in user
    var contactGR = new GlideRecord('customer_contact');
    contactGR.addQuery('sys_id', userSysId);
    contactGR.query();
		
    if (contactGR.next()) {
        var mainAccountSysId = contactGR.account.toString();
        if (mainAccountSysId) {
            addAccount(mainAccountSysId);
            fetchChildAccounts(mainAccountSysId);
        }
    }
    
    // --- Step 2: Find additional accounts through contact relationships
    var relationshipGR = new GlideRecord('sn_customerservice_contact_relationship');
    relationshipGR.addQuery('contact', userSysId);
    relationshipGR.query();
    while (relationshipGR.next()) {
        var companySysId = relationshipGR.company.toString().trim();
        if (companySysId) {
            addAccount(companySysId);
            fetchChildAccounts(companySysId);
        }
    }
    
    // --- Helper functions ---
    function addAccount(sysId) {
        var accGR = new GlideRecord('customer_account');
        if (accGR.get(sysId)) {
            var accountName = accGR.name.toString();
            data.accounts.push({
                sys_id: accGR.getUniqueValue(),
                name: accountName
            });
            
            // Fetch attachments for this account
            fetchAttachments(sysId, accountName);
        }
    }
    
    function fetchChildAccounts(parentSysId) {
        var childGR = new GlideRecord('customer_account');
        childGR.addQuery('account_parent', parentSysId);
        childGR.query();
				gs.info("SV 50: Number of child accounts for " + parentSysId + " is " + childGR.getRowCount());
        while (childGR.next()) {
            var childId = childGR.getUniqueValue();
            if (!accountExists(childId)) {
                addAccount(childId);
                fetchChildAccounts(childId);
            }
        }
    }
    
    function accountExists(sysId) {
        return data.accounts.some(function(account) {
            return account.sys_id === sysId;
        });
    }

    function fetchAttachments(accountSysId, accountName) {
        var attGR = new GlideRecord('sys_attachment');
        attGR.addQuery('table_sys_id', accountSysId);
        attGR.query();
        while (attGR.next()) {
            data.attachments.push({
                sys_id: attGR.getUniqueValue(),
                file_name: attGR.file_name.toString(),
                account_sys_id: accountSysId,
                account_name: accountName
            });
        }
    }
	
})();

 

Requirement is to fetch the parent and the corresponding child accounts.

When the parentSysId is fetched from customer_contact (which is in gloabl scope), i am able to get the child accounts.

When the parentSysId is fetched from sn_customerservice_contact_relationship (which is in Customer Service scope), i am not able to get the child accounts.

When I run this part of the script as background script (with the sysid from sn_customerservice_contact_relationship), I can see all the child accounts.

 

 var childGR = new GlideRecord('customer_account');
        childGR.addQuery('account_parent', parentSysId);
        childGR.query();
				gs.info("SV 50: Number of child accounts for " + parentSysId + " is " + childGR.getRowCount());
        while (childGR.next()) {
            var childId = childGR.getUniqueValue();
            if (!accountExists(childId)) {
                addAccount(childId);
                fetchChildAccounts(childId);
            }
        }

 

The widget is in Customer Service scope. How do I resolve this issue?

 

 

1 ACCEPTED SOLUTION

vidhya_mouli
Giga Sage

I found the issue. It is an ACL issue. The user is not able to access the child account when he is mentioned in Customer User Relationship. This is because of the Business Rule: Account query rules.

View solution in original post

5 REPLIES 5

vidhya_mouli
Giga Sage

I found the issue. It is an ACL issue. The user is not able to access the child account when he is mentioned in Customer User Relationship. This is because of the Business Rule: Account query rules.