Help with OnCellEdit Client Script

CharlieDev37
Tera Contributor

Hello Experts,

 

I have a development request that I am working on and I need clarity.  I was requested to make a modification to functionality on the hardware table (alm_hardware).  When the state of a record is changed on the form a custom field (Last Status Changed) should update with the time and date of when the field was modified.  This was completed using an OnChange Client Script.  Additionally, the request asks that if a user makes a change to the state field from list view then it should also update that field (Last Status Changed) on the list view.  This is where I am having some issues.  I tried creating an OnCellEdit Client script to resolve this ask, but the CS is not functioning properly.  Can someone provide some insight on what I have done incorrectly and how to resolve.  Thanks

1 REPLY 1

Bhavya11
Kilo Patron

Hi @CharlieDev37 ,

Client script is not working because No, it is not available since you are not on a form (hence g_form).

try something like below 
Oncelledit CS

 

function onCellEdit(sysIDs, table, oldValues, newValue, callback) {
    var saveAndClose = true;

 
    var GroupMemberCheck = new GlideAjax('GetLocationsByRegion');
    GroupMemberCheck.addParam('sysparm_name', 'gettimenow');
    GroupMemberCheck.addParam('sysparm_ids', sysIDs); //sysid of record
    GroupMemberCheck.getXML(alertRegion);

    function alertRegion(response) {
        var rep = response.responseXML.documentElement.getAttribute("answer");
		
    }


    // Remove this line to ensure the callback is only called once in the async response
    callback(saveAndClose);


}

 

 

Script include:

 

var GetLocationsByRegion = Class.create();
GetLocationsByRegion.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    gettimenow: function() {
        var regionId = this.getParameter('sysparm_ids');
		gs.log("inside"+regionId);
        var gr = new GlideRecord("incident");
        gr.addQuery("sys_id","IN", regionId);
        gr.query();
        if (gr.next()) {
            gr.u_on_old_until = new GlideDateTime(); //update custom field here
            gr.update();
        }

    },

});

 

 

If my response proves useful, please indicate its helpfulness by selecting "Accept as Solution" and " Helpful. 

 

Thanks,

BK