how can we search records based on created date in glide record query?

Ruhee1
Mega Contributor

Hi All,

I am working on requirement where a UI action will show all the related task based on assessment. I am facing two issues while developing this -

  1. From UI action code, I am unable to pass sys_created_on value of current record through Glide Ajax. Please find code below - 

    var vendor = g_form.getValue('vendor');
    var mainVendor = '';
    var assessmentId = '';

    var gajax = new GlideAjax("abc");
    gajax.addParam("sysparm_name", "getMainVendor");
    gajax.addParam("sysparm_vendorId", vendor);

    gajax.getXMLAnswer(getMainVendor1);  I have tried with many ways but nothing is working - //var gdt = new GlideDateTime(current.sys_created_on);
    //var cr = g_form.getValue('sys_created_on'); //var date_number = getDateFromFormat(g_form.getValue('sys_created_on')); 

  2. Second issue, in scrip include, how can we check records created on same date in glide record query. var num = this.getParameter('sysparm_create_date'); 

    if (mainVendor != '') {
    var commonTPQId = gs.getProperty('&&&&&&&&');

    var assessmentNumber = '';
    var grVRA = new GlideRecord("sn_vdr_risk_asmt_assessment");
    grVRA.addQuery("vendor", mainVendor);
    grVRA.addQuery("assessment_template", &&&&&&&);
    //grVRA.addQuery("sys_created_on", crD1); Any help on this two issues will be grateful. 

3 REPLIES 3

Anshu_Anand_
Kilo Sage

In UI action pass sys_created_on as sysparm_created something like this

var created_on = g_form.getValue('sys_created_on');
gajax.addParam("sysparm_created",created_on);

 

On script include, the query part

var dt= this.getParameter('sysparm_created');
var gdt = new GlideDateTime(dt);
var d= gdt.getDate(); // date part extracted

var grVRA = new GlideRecord("sn_vdr_risk_asmt_assessment");
var que = "sys_created_onON"+d+"@javascript:gs.dateGenerate('"+d+"','start')@javascript:gs.dateGenerate('"+d+"','end')";
grVRA.addEncodedQuery("sys_created_on", que);
gr.query();

Let me know in case of queries.

 

Please mark answer as correct if helpful

Hi Anshu,

Thanks for your reply. The solution you have provided is not working as I have told before I am unable to get sys_created_on by using 

g_form.getValue('sys_created_on');

There is some issue with this. Just for additional information, this UI action is in scoped application, could this be an issue?

You have to pass sys_id to the script include from UI action

var sysid = g_form.getUniqueValue();
gajax.addParam("sysparm_created",sysid);

And on script include you need to glide record your table to fetch the sys_created_on date

var dt="";
var sysid= this.getParameter('sysparm_sysid');
var gr = new GlideRecord("<table>"); //table name
gr.addQuery('sys_id',sysid);
gr.query();
if(gr.next())
	{
	dt = new GlideDateTime(gr.sys_created_on);
	}

I tried in my PDI for one of the tables, it works 

UI action

find_real_file.png

script include

find_real_file.png

result

find_real_file.png

Hope you have both script include and UI action in same scope

 

Mark answer as correct if its helpful