Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Script Include for reference qualifier

Nataliia_Lova
Tera Guru

Hi there, 

I need restrict options on Location Dropdown to patient addresses. Required conditions are:

  • Where “Type” = Health Location or Health Depot, OR

  • Where the linked Consumer on the location is the same as the Consumer on the Patient associated with a WOT

I wrote the Reference Qualifier in Dictionary Entry Override: 

cmn_location_type=health_location^ORcmn_location_type=health_depot^ORconsumer="+current.work_order.x_table_patient_name.consumer 

However, only the first condition works (Type = Health Location or Health Depot).
The condition with consumer="+current.work_order.x_table_patient_name.consumer does not seem to be working.

My manager suggested me to use this Script Include methods for the reason: 

getLocationAndTerritoryHospitalIDsForConsumerFromGr: function(gr) {
        var consumer_sysid = '';
        var table = gr.getTableName();
        if (table == 'sn_hcls_appointment') {
            consumer_sysid = gr.patient.consumer;
        }
        if (table == 'wm_task') {
            consumer_sysid = gr.work_order.u_appointment.patient.consumer;
        }
        return this.getLocationIDsForConsumer(consumer_sysid).join('^NQ');
    },

    getLocationIDsForConsumerFromGr: function(gr) {
        var consumer_sysid = '';
        var table = gr.getTableName();
        if (table == 'sn_hcls_appointment') {
            consumer_sysid = gr.patient.consumer;
        }
        if (table == 'wm_task') {
            consumer_sysid = gr.work_order.u_appointment.patient.consumer;
        }
        return this.getLocationIDsForConsumer(consumer_sysid)[0];
    },

    getLocationIDsForConsumer: function(consumer_sysid) {
        /* returns location sysids in array */
        var consumerSysID = '';
        if (consumer_sysid) {
            consumerSysID = consumer_sysid;
        } else {
            consumerSysID = this.getParameter('sysparm_consumer_sysid');
        } // end if else make client callable as well
        var locationIDs = [];
        var territoryIDs = [];
        var state = '';
        var tableName = 'cmn_location';
        var encQry = 'consumer.sys_id=' + consumerSysID;
        var gr = new GlideRecord(tableName);
        gr.addEncodedQuery(encQry);
        gr.query();
        var getRowCount = gr.getRowCount();
        while (gr.next()) {
            var locationSysID = gr.sys_id.toString();
            var locationName = gr.name;
            locationIDs.push(locationSysID);
            if (gr.u_territory) territoryIDs.push(gr.u_territory.toString());
            state = gr.state.toString();
            gs.info('locationName ' + locationName + '\n' + 'locationSysID ' + locationSysID);
        }
        var locationSYSIDs = 'sys_idIN' + locationIDs.toString();
        var territoryHospitalSYSIDs = 'cmn_location_typeINhealth_depot,health_location^ORDERBYconsumer';
        /*if (territoryIDs.length > 0) { // add a territory filter
            territoryHospitalSYSIDs += '^u_territoryIN' + territoryIDs.toString();
        } else { //else filter by state
            if (state) territoryHospitalSYSIDs += '^state=' + state;
        }*/
        return [locationSYSIDs, territoryHospitalSYSIDs];

    },

    getstringback: function(given) {
        var answer = given;

        return answer;
    }

My questions are:

  1. Should this Script Include be client-callable, server-callable?

  2. Since the Script Include returns an array, and a Reference Qualifier must be a string, how can I use these methods in a Reference Qualifier?

Thanks in advance!

5 REPLIES 5

Bert_c1
Kilo Patron

If you get what you want in Scripts Background, then use the something like:

 

javascript:'sys_idIN'+new sn_customerservice.CaseTaskHelper().getCaseTaskAccounts(current);

in the 'Reference qual' field. This is from an existing OOB dictionary record for Account on the sn_customerservice_task record. (replace ':' with ':' in the above.