Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business rule on database views logic not working

jitendrag
Tera Expert

I have a database view which connects outages and change requests. I have a created a before Query business rule to add filters and check condition if begin date in outage is equal to 4 days from today. I have created the below logic. But i am not getting the value of oa_begin which is the begin date field in outage form. Can anyone please help me.

 

 var todayDate = new GlideDateTime();
        todayDate.addDays(4);
if (oa_begin == todayDate) {

            current.addQuery('oa_type', 'planned');
            var queryString = "cr_state=-2^Orcr_state=-1";
            current.addEncodedQuery(queryString);
        }
1 ACCEPTED SOLUTION

Hi @jitendrag ,
Try below code

 var todayDate = new GlideDateTime();
    var fourDaysFromNow = new GlideDateTime();
    fourDaysFromNow.addDaysUTC(4);
    var fourDaysDateString = fourDaysFromNow.getDisplayValue().split(' ')[0];
    var oaBegin = current.getValue('oa_begin').split(' ')[0];
    if (oaBegin == fourDaysDateString) {
        current.addQuery('oa_type', 'planned');
        current.addEncodedQuery("cr_state=-2^ORcr_state=-1");
    }

Thanks,

Anand

View solution in original post

3 REPLIES 3

Anand Kumar P
Giga Patron

Hi @jitendrag ,

Try to gliderecord outage table as below

var todayDate = new GlideDateTime();
    todayDate.addDays(4);
    var outageGR = new GlideRecord('outage');
    outageGR.addQuery('oa_begin', todayDate);
    outageGR.query();
    if (outageGR.next()) {
        current.addQuery('oa_type', 'planned');
        var queryString = "cr_state=-2^ORcr_state=-1";
        current.addEncodedQuery(queryString);
    }

Please mark it as helpful and solution proposed if it works for you.

Thanks,

Anand

Hi @Anand Kumar P 

 

This solution is not working for me. It was not going into into the while loop

Hi @jitendrag ,
Try below code

 var todayDate = new GlideDateTime();
    var fourDaysFromNow = new GlideDateTime();
    fourDaysFromNow.addDaysUTC(4);
    var fourDaysDateString = fourDaysFromNow.getDisplayValue().split(' ')[0];
    var oaBegin = current.getValue('oa_begin').split(' ')[0];
    if (oaBegin == fourDaysDateString) {
        current.addQuery('oa_type', 'planned');
        current.addEncodedQuery("cr_state=-2^ORcr_state=-1");
    }

Thanks,

Anand