in catalog form i will keep the values form sla (contract_sla) table, but it will not working

Gillerla Rajesh
Tera Contributor

in catalog form i need to keep the values form sla (contract_sla) table, i need the duration type and duration value and keep in service portal form, but it will not working.

based on company field (reference - core_company)

and Target- Response, resolution, Response To Site ( choice field)

 i will get duration type and duration filed value and set it in the form.

GillerlaRajesh_0-1710849126912.png

 

GillerlaRajesh_1-1710849671582.png

 

any one help me, 

 

this is the script  i tried but it will not entering into the contract_sla table,

 

Script incude:

-----------------------------

 getSLA: function() {
        var company = this.getParameter('sysparm_company');
        var slatype = this.getParameter('sysparm_sla');

        var com = new GlideRecord('core_company');
        com.addQuery('sys_id', company);
        gs.log('company ' + company);
        com.query();
        if (gr.next()) {

            var sla = new GlideRecord('contract_sla');
            sla.addQuery('u_company', company);
            gs.log('inside' + company);
            sla.addQuery('target', slatype);
            //sla.addQuery('name','Adidas_Break_Fix_Triage_P4');
            gs.log('here' + slatype);
            //sla.groupBy('target');
            sla.query();
            if (sla.next()) {
                return sla.duration;
            }
        }
    },
   
 
catalog client script:
--------------------------------
var typeOfSLA=g_form.getValue('type_of_sla');
var company=g_form.getValue('company');
var ga=new GlideAjax('getSLADurationDetails');
ga.addParam('sysparm_name','getSLA');
ga.addParam('sysparm_company',company);
ga.addParam('sysparm_sla',typeOfSLA);

ga.getXML(slaDuration);

function slaDuration(response)
{
    var res=response.responseXML.documentElement.getAttribute("answer");
    alert(res);
    //g_form.addOption('associated_resolution_sla',res);
}
 
 
 
any one can suggest me how can i achive this.
4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

You haven't shared if you are receiving any of the logs in the Script Include.  You don't need the first GlideRecord in the Script Include since you're passing in a sys_id from a reference variable on the core_company table, you know it is valid as long as it is received into the Script Include.  You should always return something, this will help troubleshooting.  Your logs should have a unique and common prefix so you can easily search through the voluminous system log to find them, if they exist.  Your if(gr.next()) condition is never met as gr is undefined.  The below code will get you closer, assuming your u_company custom field on the contract_sla table is a reference to core_company, and the slatype variable value matches the target field value, which you can confirm from the logs.  The duration field value will be a seemingly meaningless number, so you may need to do something with it before returning it to the client to get it in the format you're looking for in the variable value assignment.

 

getSLA: function() {
		gs.log('SI running');
		var answer = '';
        var company = this.getParameter('sysparm_company');
        var slatype = this.getParameter('sysparm_sla');
		gs.log('SI company ' + company);
		gs.log('SI slatype ' + slatype);
        var sla = new GlideRecord('contract_sla');
        sla.addQuery('u_company', company);
        sla.addQuery('target', slatype);
        //sla.addQuery('name','Adidas_Break_Fix_Triage_P4');
        //sla.groupBy('target');
        sla.query();
        if (sla.next()) {
            gs.log('SI contract found ' + sla.name
            answer = sla.duration;  
        }
        return answer;
},

 

 

 

Hi @Brad Bowman  ,

 

in sla table (contract_sla), it will not returning any log.

 

log is coming in comany (core_company ) table, that's it after it not returning any log

That would be expected with your original script, given the if(gr.next()) error.  Let me know the results of my proposed script.

Hi @Brad Bowman  ,

 

thanks for your reply,

now it's working fine. and logs are getting.

 

Regards

Rajesh.