onChange client script with Script Include issue.

Kvb Kiran
Tera Expert
  1. We have two forms, Form1 and Form2 (catalog items), which can be triggered either individually or sequentially.
  2. Both Form1 and Form2 are configured with similar variables that are automatically populated using onLoad and onChange client scripts.
  3. When Form1 is submitted, an HR Case (HRC) is created with all the catalog variables stored in the HR Case Variables section. After the HRC is created, a flow runs that associates the HRC with a parent ticket, which is created after the HRC. All variables from Form1 are visible in the variables section of the HRC.
  4. On loading Form2, there is logic in place (using a client script and a script include) to populate the parent ticket. At this stage, the parent ticket is already associated with the HRC and is loaded as soon as Form2 opens. I attempted to retrieve two variables from the related HRC during this process.
  5. The new requirement is to fetch variables from the HRC and apply them to Form2 during the onChange event of the parent ticket field.
  6. Currently, we only need to retrieve two variables:
  • One checkbox
  • One select box

I have tried multiple approaches to fetch these variables but have not been successful.

Could someone please assist with the required code or approach?


Script include was added with glideajax processor and client callable. The script include was a part of lot other functions. So i was just adding the function that was using.

 

For now, i am trying to get at least one value. Later i will add the second variable as well.

 

Client script

function onChange(newValue, isLoading) {
    if (isLoading || !newValue) {
        return;
    }
    var getHRApproval = new GlideAjax('script_include.Utils');
    getHRApproval.addParam('sysparm_name', 'getHRApprovalCheckandSelect');
    getHRApproval.addParam('sysparm_universal', newValue);
    getHRApproval.getXML(function(answer) {
        g_form.setValue('is_checkbox', answer === '1' ? '1' : '0');
    });
}

 

Script Include function

getHRApprovalCheckandSelect: function() {

        var universal = this.getParameter('sysparm_universal');
        var getHRApprovalCS = new GlideRecord('sn_hr_core_case');
        getHRApprovalCS.addQuery('parent', universal);
        getHRApprovalCS.addQuery('u_record_producer', gs.getProperty('rp.offer_position'));
        getHRApprovalCS.orderByDesc('sys_created_on');
        getHRApprovalCS.query();

        if (getHRApprovalCS.next() && getHRApprovalCS.variables && getHRApprovalCS.variables.is_checkbox) {
            var v = getHRApprovalCS.variables.is_checkbox.toString();
            if (v === 'true' || v === '1' || v === 'Yes') {
                value = '1';
            }
        }
        return value;

 

Thanks,

Kiran.


0 REPLIES 0