Advanced user criteria for Business portal

mariasilva
Tera Contributor

I need to create a user criteria that meets the following criteria: The Contract table is ast_contract, the Contact table is customer_contact, and the Account table is customer_account. This should be an advanced user criteria with a script to check the current contact in the portal, considering the contacts in the Contact tab of the customer_account table, query all ACTIVE contracts for the account they are part of, and then query, depending on whether they are AMS criteria, the sys_id of the contract model found in the sn_b2b_portal.glide.sc.portal.ams_contract_models property. If the glidequery contains next, that is, there is at least one record, return true; otherwise, return false.

I created this code, but it's not working. Could someone please help me?

 

(function() {
    var contact = gs.getUser().getID();
    var account = new GlideRecord('customer_account');
    account.addQuery('contact', contact);
    account.query();

    if (account.next()) {
        var contract = new GlideRecord('ast_contract');
        contract.addQuery('account', account.sys_id);
        contract.addActiveQuery();

        var maintModels = gs.getProperty('sn_b2b_portal.glide.sc.portal.maintenance_contract_models').split(',');
        contract.addQuery('contract_model''IN', maintModels);
        contract.query();

        return contract.hasNext();
    }
    return false;
1 REPLY 1

Hemanth M1
Giga Sage
Giga Sage

Hi @mariasilva ,

 

Can you try this 

var account = new GlideRecord('customer_account');
    account.addQuery('contact', user_id); //user_id to get logged in user sys_id
    account.query();
    if (account.next()) {
        var contract = new GlideRecord('ast_contract');
        contract.addQuery('account', account.sys_id);
        contract.addActiveQuery();
contract.query() //to get initiate the query to retrive records
var maintModels = gs.getProperty('sn_b2b_portal.glide.sc.portal.maintenance_contract_models').split(',');
       contract.addQuery('contract_model', 'IN', maintModels);
        contract.query();
        return contract.hasNext();
    }
    return false;

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025