Updating HR profile value

sanvi
Tera Expert

Hi All,

 

I have a requirement for adding 'User HR profile' value in Associated Allgetaion table.

So i have created a custom field on 'Associated Allegations' table called USER HR PROFILE which is a reference field referring to user HR profile table. I am trying to populate the value on this field based on the 'Subjects of Allegation' field value. So to achieve this i have configured the below business rule.

 

When : Before -Update

var prof = current.involved_party;
    gs.addInfoMessage("value of subject of allegation"+ prof);
    var hrProf = new GlideRecord('sn_hr_core_profile');
    hrProf.addEncodedQuery('user='+prof);
    hrProf.query();
 
    if(hrProf){
        gs.addInfoMessage("value of subject of allegation inside loop"+ hrProf.user );
 
        current.setValue('u_user_hr_profile', hrProf.user.u_name);
        current.update();
}
   
I am getting undefined value for this Info message
sanvi_0-1748411262585.png

 

Can anyone suggest.

 
7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@sanvi 

update as this

I assume field "u_user_hr_profile" refers to HR Profile table

var prof = current.involved_party;
gs.addInfoMessage("value of subject of allegation" + prof);
var hrProf = new GlideRecord('sn_hr_core_profile');
hrProf.addEncodedQuery('user=' + prof);
hrProf.query();

if (hrProf.next()) {
    gs.addInfoMessage("value of subject of allegation inside loop" + hrProf.user);

    current.setValue('u_user_hr_profile', hrProf.getUniqueValue());
    current.update();
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@sanvi 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

No the above script is not working.

It seems that script is not entering the if condition as i am not getting the info message inside the script.

 

Yes "u_user_hr_profile" refers to HR Profile table.

 

 

 

@sanvi 

the field "involved_party" is referring to sys_user?

If yes then did you check if any HR profile is present for that user? then only it will enter IF

If my response helped please mark it correct and close the thread so that it benefits future readers.

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader