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.

want to take employee start date from HR profile

abirakundu23
Giga Sage

Hi All,

I  take employeement start date  from HR profile and set the value in sn_hr_core_case  table.

I have wrote code . After/update on case table but it is not working. Please look into this.

(function executeRule(current, previous /*null when async*/) {

//     var basecurrency = current.u_currency;
//     var split1 = basecurrency.split(' ').slice(0, 1).join(' ');
//     gs.addInfoMessage("Check done:" +split1);
    gs.addInfoMessage("hello world test");
    var ga1 = new GlideRecord("sn_hr_core_profile");
    ga1.addQuery("user",name);
    ga1.query();
    if(ga1.next())
        {
            current.u_itpend_date=ga1.employment_start_date;
            
            current.update();
        }
gs.info("hiiiiiiiiiiiiiiiiii");
})(current, previous);

6 REPLIES 6

Mohith Devatte
Tera Sage
Tera Sage

hello @absnow 

if you trying to update the current logged in user employment start date then you might have to change the query 

ALSO USING CURRENT.UPDATE() IS NOT A BEST PRACTICE IN AFTER INSERT OR UPDATE BUSINESS RULE SO I HAVE GLIDE RECORDED TO THE CURRENT TABLE AND UPDATED THE FIELD .TRY THE BELOW SCRIPT ONCE

  var ga1 = new GlideRecord("sn_hr_core_profile");
    ga1.addQuery("user",gs.getUserID());
    ga1.query();
    if(ga1.next())
        {
var gr = new GlideRecord(current.getTableName())
gr.addQuery('sys_id',current.sys_id);
gr.query();
if(gr.next())
{
           gr.u_itpend_date=ga1.employment_start_date;
            
           gr.update();
        }

})(current, previous);

Hope this helps 

MARK THE ANSWER CORRECT IF THIS HELPS YOU

Hi @Mohith Devatte ,

I have write code on "sn_hr_core_case" table.

(function executeRule(current, previous /*null when async*/) {

    var ga1 = new GlideRecord("sn_hr_core_profile");
    ga1.addQuery("user",gs.getUserID());
    ga1.query();
    if(ga1.next())
        {
var gr = new GlideRecord(current.getTableName());
gr.addQuery('sys_id',current,sys_id);
gr.query();
if(gr.next())
{
           gr.u_itpend_date=ga1.employment_start_date;
            
           gr.update();
        }
        }

})(current, previous);

 

not running on case table after br. not set employment date on u_itpend_date field.

hello @absnow try this

(function executeRule(current, previous /*null when async*/) {

    var ga1 = new GlideRecord("sn_hr_core_profile");
    ga1.addQuery("user",gs.getUserID());
    ga1.query();
    if(ga1.next())
        {
var gr = new GlideRecord('sn_hr_sore_case');
gr.addQuery('sys_id',current.sys_id);
gr.query();
if(gr.next())
{
           gr.u_itpend_date=ga1.employment_start_date;
            
           gr.update();
        }
        }

})(current, previous);

Hi Mohith,

I reruire opened for user employement date not current login user. It is not working.

(function executeRule(current, previous /*null when async*/) {
gs.addInfoMessage("hello world");
    var ga1 = new GlideRecord("sn_hr_core_profile");
    ga1.addQuery("user","opened_for");
    ga1.query();
    if(ga1.next())
        {
var gr = new GlideRecord('sn_hr_core_case_global_mobility');
gr.addQuery('sys_id',current.sys_id);
gr.query();
if(gr.next())
{
           gr.u_itpend_date=ga1.employment_start_date;
            
           gr.update();
        }
        }
gs.addInfoMessage("hello world");
})(current, previous);