Hi,
I have set the due date and the SLA days based on Item field and i need to merge the two script include and two client scripts into one as both are from the same table and the code is the almost the same as well.
Code:
To get the due date and SLA days(Client script):
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.addInfoMessage("To get due date client script");
var getSlaValue = "";
if (g_form.getValue('u_state') != 4 && g_form.getValue('u_state') != 5)
{
getSlaValue = "YES";
}
else if (g_form.getControl('u_state').changed && g_form.getValue('u_state') == 4 || g_form.getValue('u_state') == 5 )
{
getSlaValue = "YES";
}
else
{
getSlaValue = "No";
}
if (getSlaValue == "YES")
{
var cat = g_form.getValue('u_category');
var subcat = g_form.getValue('u_sub_category');
var itm = g_form.getValue('u_item');
g_form.setValue("u_due_date","");
var ajax = new GlideAjax('MyDateTimeAjax');
ajax.addParam('sysparm_name', 'nowDateTime');
ajax.addParam('sysparm_cat', cat);
ajax.addParam('sysparm_subcat', subcat);
ajax.addParam('sysparm_itm', itm);
ajax.getXML(getResponse);
}
function getResponse(response)
{
var slaResult = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('u_due_date', slaResult);
}
}
The only change happening to get the SLA days in the other client script is the last function line:
g_form.setValue("u_sla_days",slaResult);
Script Include:
MyDateTimeAjax = Class.create();
MyDateTimeAjax.prototype = Object.extendsObject(AbstractAjaxProcessor,
{
nowDateTime: function ()
{
gs.log("MyDateTimeAjax");
var nd = new GlideDateTime(gs.nowDateTime());
gs.log("nd value is" + nd);
var cat = this.getParameter('sysparm_cat');
var subcat = this.getParameter('sysparm_subcat');
var itm = this.getParameter('sysparm_itm');
var gr = new GlideRecord("u_sla_admin_details");
gr.addQuery("u_category", cat);
gr.addQuery("u_sub_category", subcat);
gr.addQuery("u_item", itm);
gr.addQuery("u_record_type", "ADMIN");
gr.addQuery("u_active", "true");
gr.query();
if(gr.next())
{
var slaResult = (gr.u_ttr * 1 );
var slaCall = "";
if (gr.u_sla_days != "")
{
slaCall = (gr.u_sla_days * 1);
if(nd.getDayOfWeekUTC() == 6)
{
nd.addDaysLocalTime(2);
}
else if(nd.getDayOfWeekUTC() == 7)
{
nd.addDaysLocalTime(1);
}
nd.addDaysUTC(slaCall);
if(nd.getDayOfWeekUTC() == 6 )
{
nd.addDaysLocalTime(2);
}
else if(nd.getDayOfWeekUTC() == 7)
{
nd.addDaysLocalTime(1);
}
return nd;
}
else
{
slaCall = "Not Applicable";
nd = slaCall;
gs.log("Inside MyDateTimeAjax else part nd value: " + nd);
return nd;
}
}
}
});
var Admin_Get_SLA_Days = Class.create();
Admin_Get_SLA_Days.prototype = Object.extendsObject(AbstractAjaxProcessor, {
sla_days_value:function()
{
var cat = this.getParameter('sysparm_cat');
var subcat = this.getParameter('sysparm_subcat');
var itm = this.getParameter('sysparm_itm');
var gr = new GlideRecord("u_sla_admin_details");
gr.addQuery("u_category", cat);
gr.addQuery("u_sub_category", subcat);
gr.addQuery("u_item", itm);
gr.addQuery("u_record_type", "ADMIN");
gr.addQuery("u_active", "true");
gr.query();
if(gr.next())
{
var slaResult = (gr.u_ttr * 1);
var slaCall = "";
if (gr.sla_days != "")
{
slaCall = (gr.u_sla_days * 1); //1
return (slaCall + " Day(s)");
}
else if (gr.sla_days == "")
{
slaCall = "Not Applicable";
return (slaCall);
}
}
},
});
The bold coded lines are the changes that has to be merged.
Please help me out with this