How to set Yes/No based on sn_si_incident table cmdb_ci matched

Ajay Singh2
Tera Contributor

Hello All,

I need a requirement like when i raise a request in Hardware Refresh Model than a task will create and in SCTASK there is a field investigation_resolution_code option when i select lost or Stolen in this dropdown based on this need to check sn_si_incident table assets is linked with cmdb_ci and if its present than set yes or no in below new field that is sir_submitted.

 

We will create a new read-only field called ā€œSIR Submitted:ā€ that will have Yes/No values. If the asset is marked as Lost or Stolen this field will appear and we will query the SIR table for a record from the user for the device ID or cmdb_ci. If a record exists we will set the field value to ā€œYesā€, if not the value is ā€œNoā€. The goal here is to NOT grant access to the SIR record for the user so this search needs to be performed on the backend and will not be editable by the user.

 

Thank You!!

3 REPLIES 3

Murthy Ch
Giga Sage

@Ajay Singh2 

Where do you want to implement this scenario?
Is it flow or workflow or BR?

Thanks,
Murthy

Hello Murthy

Need to implement this in SCTASK when mapping sn_si_incident table cmdb_ci and this need to be done by Script Include and Client Scripts.

 

Thank You!!

Tai Vu
Kilo Patron
Kilo Patron

Hi @Ajay Singh2 

Let give my script a try. Just need to change the field name and choice value according to your case.

Client Script OnChange investigation_resolution_code

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        return;
    }

    if (newValue === '' || (newValue !== 'Lost' && newValue !== 'Stolen')) { //replace your choice value for Lost and Stolen
        g_form.setValue('sir_submitted', '');
        return;
    }

    var ga = new GlideAjax('HardwareRequestUtils');
    ga.addParam('sysparm_name', 'sirSubmitted');
    ga.addParam('sysparm_device_id', g_form.getValue('<your_asset_variable>')); //replace your variable for asset or ci
    ga.getXMLAnswer(function(response) {
        if (response === 'true') {
            g_form.setValue('sir_submitted', 'Yes');
            return;
        }
        g_form.setValue('sir_submitted', 'No');
    });

}

 

Script Include Client Callable

var HardwareRequestUtils = Class.create();
HardwareRequestUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	sirSubmitted: function(){
		var deviceId = this.getParameter('sysparm_device_id');
		var grSIR = new GlideRecord('sn_si_incident');
		grSIR.addQuery('cmdb_ci', deviceId); //replace field name for asset or ci
		grSIR.query();
		return grSIR.hasNext();
	},

    type: 'HardwareRequestUtils'
});

 

Cheers,

Tai Vu