Untitled
unknown
plain_text
2 years ago
24 kB
9
Indexable
(function executeRule(current, previous /*null when async*/ ) {
var sourcedfrom;
var up = new GlideRecord("sys_user");
var sub_per = current.subject_person.getDisplayValue();
up.addQuery('name', sub_per);
up.query();
while (up.next()) {
sourcedfrom = up.u_sourced_from;
}
gs.info("###subject person " + sub_per);
gs.info('Sourced from outside JSON ' + sourcedfrom);
var paygrade=current.subject_person_hr_profile.u_pay_grade;
gs.info("####Paygrade " +paygrade);
var pg = paygrade.toLowerCase();
var pri;
if(sourcedfrom == 'Successfactors'){
pri=true;
}
var ers;
var er = current.subject_person_hr_profile.u_rehire.toString();
if (er == 'Yes') {
ers = 'REHREH';
pri = false;
} else if (er == 'No') {
ers = 'HIRNEW';
pri = true;
}
var careerbreak = current.subject_person_hr_profile.u_career_break.getDisplayValue();
var iscareerbreak;
//gs.info("careerbreak is "+careerbreak);
if (careerbreak == 'Yes') {
iscareerbreak = 'Y';
} else {
iscareerbreak = 'N';
}
var cb_reason;
var careerbreakreason = current.subject_person_hr_profile.u_career_break_reason.getDisplayValue();
//gs.info("careerbreakreason is "+careerbreakreason);
if (careerbreakreason == 'Others') {
cb_reason = 'O';
} else if (careerbreakreason == 'Self-employed') {
cb_reason = 'S';
} else if (careerbreakreason == 'Family') {
cb_reason = 'F';
} else if (careerbreakreason == 'Education') {
cb_reason = 'E';
} else {
cb_reason = null;
}
var lengthOfCB = current.subject_person_hr_profile.u_length_of_career_break.getDisplayValue();
if (iscareerbreak == 'N') {
lengthOfCB = null;
}
var lm_id = current.subject_person_hr_profile.u_line_manager.employee_number.getDisplayValue();
//gs.info("Linemanager ID " + lm_id);
var salutation = current.variables.title_g.toString();
var doctype = current.variables.document_type.toString();
var lang = current.variables.preferred_language.toString();
var eTitle = current.variables.emergency_contact_CA.getDisplayValue();
var Emrelationship = current.variables.relationship_emergency_contact_CA.toString();
var EPrimaryflag = current.variables.primary_CA.toString();
var emailtype = current.variables.email_type.toString();
var maritalstatus = current.variables.marital_status.toString();
var phonetype = current.variables.phone_type.toString();
var gender = current.variables.gender_gpi.toString();
var eventreasons = current.u_event_reasons.getDisplayValue();
var businesstype = current.variables.type_of_business.toString();
var nationality = current.variables.nationality_pi.toString();
var employeeType = current.subject_person_hr_profile.u_employee_type.toString();
var emergency_con = current.variables.emergency_contact.toString();
var epochIssueDate = current.variables.issue_date.getDisplayValue();
var offsetEpoch = epochIssueDate + ' ' + '12:00:00';
var gdt = new GlideDateTime(offsetEpoch);
gdt.setDisplayValue(offsetEpoch);
var issuedate = new Date(offsetEpoch);
var epochDate = Math.floor(gdt.getNumericValue());
var isuedate = "\/Date(" + epochDate + ")\/";
//gs.info('@@@$$%%%PP issuedateis ' + isuedate);
var epochExpirationDate = current.variables.expiry_date.getDisplayValue();
var offsetExpiry = epochExpirationDate + ' ' + '12:00:00';
var gdtepochExpirationDate = new GlideDateTime(offsetExpiry);
gdtepochExpirationDate.setDisplayValue(offsetExpiry);
//gs.info('%%%****gdt poc13 ' + gdtepochExpirationDate);
var expirationDate = new Date(offsetExpiry);
var ExpirationDate = Math.floor(gdtepochExpirationDate.getNumericValue());
//gs.info('%%%****ExpirationDate ' + ExpirationDate);
var ExpirationDate1 = "\/Date(" + ExpirationDate + ")\/";
//gs.info('expirartobkjlml %%%980- ' + ExpirationDate1);
var epochDOB = current.variables.date_of_birth.getDisplayValue();
var offsetDOB = epochDOB + ' ' + '12:00:00';
var gdtDOB = new GlideDateTime(offsetDOB);
gdtDOB.setDisplayValue(offsetDOB);
//gs.info('gdtDOBBB ' + gdtDOB);
var DOB = new Date(offsetDOB);
var DateOfBirth = Math.floor(gdtDOB.getNumericValue());
//gs.info('&&&DOB ' + DateOfBirth);
var updateDOB = "\/Date(" + DateOfBirth + ")\/";
var srcfrm = sourcedfrom.toLowerCase();
//gs.info("srcfrom lower case " + srcfrm);
//gs.info('Sourced from outside JSON ' + sourcedfrom);
//var epochStartDate = current.variables.hire_date.getDisplayValue();
var epochStartDate = current.subject_person_hr_profile.employment_start_date.getDisplayValue();
//gs.info('Subject Person Hire date is ' + epochStartDate);
var offsetHire = epochStartDate + ' ' + '12:00:00';
var gdtHiredate = new GlideDateTime(offsetHire);
gdtHiredate.setDisplayValue(offsetHire);
var startDate = new Date(offsetHire);
var startdate = Math.floor(gdtHiredate.getNumericValue());
var hireDate = "\/Date(" + startdate + ")\/";
//gs.info('empHIreDate ' + hireDate);
// var epochEndDate = current.subject_person_hr_profile.employment_start_date;
// var gdt = new GlideDateTime(epochEndDate);
// gdt.addYearsUTC(50);
// var offsetEnd = gdt + ' ' + '12:00:00';
// var gdtEnddate = new GlideDateTime(offsetEnd);
// gdtHiredate.setDisplayValue(offsetEnd);
// var EndDate = new Date(offsetEnd);
// var EndDate = Math.floor(gdtEnddate.getNumericValue());
// var EndDate = "\/Date(" + EndDate + ")\/";
// gs.info('@@@@end date '+ EndDate);
// var termoinationDate;
// if(er == 'Yes')
// {
// termoinationDate = EndDate;
// }
// else{
// termoinationDate ='';
// }
// var strtdate1 = new GlideDateTime(epochStartDate);
// strtdate1.addDaysUTC(5);
// var offsetHire1 = strtdate1 + ' ' + '12:00:00';
// var gdtHiredate1 = new GlideDateTime(offsetHire1);
// gdtHiredate.setDisplayValue(offsetHire1);
// var startDate2 = new Date(offsetHire1);
// var startdate2 = Math.floor(gdtHiredate1.getNumericValue());
// var hireDate1 = "\/Date(" + startdate2 + ")\/";
var joiningdate = current.variables.start_date.getDisplayValue();
var offsetjoining = joiningdate + ' ' + '12:00:00';
var gdtjoiningdate = new GlideDateTime(offsetjoining);
gdtjoiningdate.setDisplayValue(offsetjoining);
var prevjoining = new Date(offsetjoining);
var prevJoiningdate = Math.floor(gdtjoiningdate.getNumericValue());
var previousempStartDate = "\/Date(" + prevJoiningdate + ")\/";
//gs.info('@@$#%previousempStartDate ' + previousempStartDate);
var End_date = current.variables.end_date.getDisplayValue();
var offsetendDate = End_date + ' ' + '12:00:00';
var gdtEndDate = new GlideDateTime(offsetendDate);
gdtEndDate.setDisplayValue(offsetendDate);
var prevEnd = new Date(offsetendDate);
var prevEndDate = Math.floor(gdtEndDate.getNumericValue());
var previousempEndDate = "\/Date(" + prevEndDate + ")\/";
//gs.info('@@$#%previousempEndDate ' + previousempEndDate);
var positionEntryDate = current.u_positionentrydate.getDisplayValue();
//var offsetposition = positionEntryDate + ' ' + '12:00:00';
var gdtposition = new GlideDateTime(positionEntryDate);
gdtposition.setDisplayValue(positionEntryDate);
var posdate = new Date(positionEntryDate);
var positionEntryDate1 = Math.floor(gdtposition.getNumericValue());
var positionDate1 = "\/Date(" + positionEntryDate1 + ")\/";
//gs.info('@@$#%positionEntryDate ' + positionDate1);
//mapping workpermitcountry -option_id
var workpermitcountry = current.variables.work_permit_country;
var wrkCountry = new GlideRecord('u_integration_mapping');
wrkCountry.addEncodedQuery('u_zone=Zone 1^u_module=HRSD - ISO Country');
wrkCountry.addQuery('u_country', workpermitcountry);
wrkCountry.query();
if (wrkCountry.next()) {
var workpermitcountry1 = wrkCountry.u_option_id.getDisplayValue();
//gs.info('workpermitcountry1 is ' + workpermitcountry1);
}
//mapping countryofbirth -externalcode
var countryofbirth = current.variables.country_of_birth.getDisplayValue();
var Country_of_birth = new GlideRecord('u_integration_mapping');
Country_of_birth.addEncodedQuery('u_zone=Zone 1^u_module=HRSD - Country');
Country_of_birth.addQuery('u_country', countryofbirth);
Country_of_birth.query();
if (Country_of_birth.next()) {
var countryofbirth1 = Country_of_birth.u_external_code.getDisplayValue();
//gs.info('countryofbirth1 is ' + countryofbirth1);
}
var NidCountry = current.variables.nid_country.getDisplayValue();
var nidcountry = new GlideRecord('u_integration_mapping');
nidcountry.addEncodedQuery('u_zone=Zone 1^u_module=HRSD - National ID country');
nidcountry.addQuery('u_country', NidCountry);
nidcountry.query();
if (nidcountry.next()) {
var nidcountry1 = nidcountry.u_external_code.getDisplayValue();
//gs.info('nidcountry1 is ' + nidcountry1);
}
//national_id_card_type
var Nid_cardtype = current.variables.national_id_card_type;
var cardtype = new GlideRecord('u_integration_mapping');
cardtype.addEncodedQuery('u_module=HRSD - National ID Card Type^u_zone=Zone 1');
cardtype.addQuery('u_external_code', Nid_cardtype);
cardtype.query();
if (cardtype.next()) {
var cardtype1 = cardtype.u_external_code.getDisplayValue();
// gs.info('cardtype1 is ' + cardtype1);
}
//Permitdoctype-document_type
var document_type = current.variables.document_type.getDisplayValue();
var Doctype = new GlideRecord('u_integration_mapping');
Doctype.addEncodedQuery('u_zone=Zone 1^u_module=HRSD - Permit Doc Type');
Doctype.addQuery('u_label', document_type);
Doctype.query();
if (Doctype.next()) {
var Doctype1 = Doctype.u_option_id.getDisplayValue();
// gs.info('Doctype1 is ' + Doctype1);
}
var data = {
"OnboardingData": {
"Header": {
"__metadata": {
"type": "SFOData.Header",
"uri": "Header"
},
"SourcedFrom": srcfrm,
"PayGrade" : pg,
},
"PerPerson": {
"__metadata": {
"type": "SFOData.PerPerson", //biographical
"uri": "PerPerson"
},
//customString1: current.variables.legacy_id_bio.getDisplayValue(),
//dateOfBirth: updateDOB,
dateOfBirth: updateDOB,
countryOfBirth: countryofbirth1,
personIdExternal: current.subject_person.employee_number.getDisplayValue(),
"customDate3": hireDate,
},
"EmpEmployment": {
"__metadata": {
"type": "SFOData.EmpEmployment",
"uri": "EmpEmployment"
},
startDate: hireDate, //previous hire date-only for rehire
seniorityDate: hireDate, //previous hire date-only for rehire
userId: current.subject_person.employee_number.getDisplayValue(),
personIdExternal: current.subject_person.employee_number.getDisplayValue(),
//eventReasons: eventreasons,
customString52: current.subject_person_hr_profile.u_source_of_hire.getDisplayValue(),
//endDate:termoinationDate,
},
"EmpJob": {
"__metadata": {
"type": "SFOData.EmpJob",
"uri": "EmpJob"
}, //line manager's EMP num-User ID
startDate: hireDate,
managerId: lm_id,
userId: current.subject_person.employee_number.getDisplayValue(),
position: current.subject_person_hr_profile.position_code.getDisplayValue(),
customDate1: hireDate,
//eventReason: eventreasons,
positionEntryDate: positionDate1,
businessUnit: current.u_businessunit.getDisplayValue(),
costCenter: current.u_costcenter.getDisplayValue(),
location: current.u_location.getDisplayValue(),
jobCode: current.u_jobcode.getDisplayValue(),
//customString21: current.u_jobcode.getDisplayValue(), //RO
//employeeClass: current.u_employeeclass.getDisplayValue(),
employeeClass: current.subject_person_hr_profile.employment_type.getDisplayValue(), //"Permanent BAT Employee",
customString101: current.subject_person_hr_profile.u_relocation_assistance.getDisplayValue(),
customString102: current.subject_person_hr_profile.u_immigration_assistance.getDisplayValue(),
company: current.u_company.getDisplayValue(),
fte: current.u_fte.getDisplayValue(),
payGrade: current.subject_person_hr_profile.u_pay_grade.getDisplayValue(),
employmentType: current.variables.legacy_employee_subgroup.getDisplayValue(),
// "customString23": "22526",
// "customString41": "No",
// "customString28" : "M5-HR-M: Hourly wage", //mexico
// "customString28" : "BR - Rio Negro",// payroll area
// "countryOfCompany" : "92",
eventReason: ers,
employeeType: employeeType,
customString28: current.subject_person_hr_profile.u_payroll_area.getDisplayValue(),
occupationalLevels: current.subject_person_hr_profile.u_occupational_level.getDisplayValue(),
customString100: current.subject_person_hr_profile.u_trade_union_member.getDisplayValue(),
customString21: current.subject_person_hr_profile.u_local_job_code.getDisplayValue(),
//customString78: current.subject_person_hr_profile.u_total_years_of_services_before_bat.getDisplayValue(),
//customDate8: current.subject_person_hr_profile.u_career_start_date.getDisplayValue(),
//eeoClass: current.subject_person_hr_profile.u_eeo_job_group.getDisplayValue(),
//customDouble1: current.subject_person_hr_profile.u_total_years_of_services_before_bat.getDisplayValue(),
customString73: current.subject_person_hr_profile.u_personal_area_personal_subarea.getDisplayValue(),
customString41: current.subject_person_hr_profile.u_first_employment_indicator.getDisplayValue(),
customString74: current.subject_person_hr_profile.u_employee_group_employee_sub_group.getDisplayValue(),
customString96: current.subject_person_hr_profile.u_collar_type.getDisplayValue(),
//customDate15: current.subject_person_hr_profile.u_career_start_date.getDisplayValue(),
//customLong1: current.subject_person_hr_profile.u_ofo_code.getDisplayValue(),
//eeo1JobCategory: current.subject_person_hr_profile.u_eeo_category_1.getDisplayValue(),
//flsaStatus: current.subject_person_hr_profile.u_flsa_status.getDisplayValue(),
customString23: current.variables.place_of_work.getDisplayValue(),
customString55: current.u_local_pay_grade.getDisplayValue(),
workingDaysPerWeek: current.subject_person_hr_profile.u_working_days_per_week.toString(),
standardHours: current.subject_person_hr_profile.u_standard_weekly_hours.getDisplayValue(),
},
"PerPersonal": {
"__metadata": {
"type": "SFOData.PerPersonal", //personal info
"uri": "PerPersonal"
},
startDate: hireDate,
firstName: current.variables.first_name.getDisplayValue(),
lastName: current.variables.last_name.getDisplayValue(),
preferredName: current.variables.pref_last_name.getDisplayValue(),
gender: gender,
maritalStatus: maritalstatus,
nationality: nationality,
salutation: salutation,
nativePreferredLang: lang,
personIdExternal: current.subject_person.employee_number.getDisplayValue(),
//secondNationality: current.variables.second_nationality.getDisplayValue(),
middleName: current.variables.middle_name_canada_per_info.getDisplayValue(),
},
"EmpWorkPermit": {
"__metadata": {
"type": "SFOData.EmpWorkPermit",
"uri": "EmpWorkPermit"
},
//country: current.variables.work_permit_country.getDisplayValue(),
country: workpermitcountry1,
//country: "70",
documentType: Doctype1,
//documentType: "9690",
documentTitle: current.variables.document_title.getDisplayValue(),
documentNumber: current.variables.document_number.getDisplayValue(),
issueDate: isuedate,
issuePlace: current.variables.issue_place.getDisplayValue(),
issuingAuthority: current.variables.issuing_authority.getDisplayValue(),
expirationDate: ExpirationDate1,
userId: current.subject_person.employee_number.getDisplayValue(),
},
"PerPhone": { //contact info
"__metadata": {
"type": "SFOData.PerPhone",
"uri": "PerPhone"
},
phoneType: phonetype,
phoneNumber: current.variables.mobile_personal.getDisplayValue(),
isPrimary: pri, //rehire
//"isPrimary":"true",
personIdExternal: current.subject_person.employee_number.getDisplayValue(),
},
"PerEmail": { //address info
"__metadata": {
"type": "SFOData.PerEmail",
"uri": "PerEmail"
},
emailType: emailtype,
emailAddress: current.variables.email_address.getDisplayValue(),
isPrimary: pri, //rehire
//"isPrimary": "true",
personIdExternal: current.subject_person.employee_number.getDisplayValue(),
},
"PerNationalId": { //NationalId
"__metadata": {
"type": "SFOData.PerNationalId",
"uri": "PerNationalId"
},
//country: current.variables.nid_country.getDisplayValue(),
country: nidcountry1,
cardType: cardtype1,
nationalId: current.variables.itin_cpf.getDisplayValue(),
isPrimary: true,
//"isPrimary":"true",
personIdExternal: current.subject_person.employee_number.getDisplayValue(),
},
"PerEmergencyContacts": {
"__metadata": {
"type": "SFOData.PerEmergencyContacts",
"uri": "PerEmergencyContacts"
},
"name": current.variables.first_name_emergency_contact_CA.getDisplayValue(), //first name
"customString1": current.variables.last_name_emergency_contact_CA.getDisplayValue(), //last name
"primaryFlag": EPrimaryflag,
//"primaryFlag": "Y",
//"primaryFlag": "true",
"customString2": eTitle, //title
"relationship": Emrelationship,
isEmergencyContact: true,
personIdExternal: current.subject_person.employee_number.getDisplayValue(),
addressCountry: "CRI", //current.variables.homeaddress_country.getDisplayValue(),
},
"Background_OutsideWorkExperience": {
"__metadata": {
"type": "SFOData.Background_OutsideWorkExperience",
"uri": "Background_OutsideWorkExperience"
},
userId: current.subject_person.employee_number.getDisplayValue(),
businessType: businesstype,
startTitle: current.variables.job_title.getDisplayValue(),
startDate: previousempStartDate,
endDate: previousempEndDate,
employer: current.variables.company_name.getDisplayValue(),
},
"EmpJobRelationships": {
"__metadata": {
"type": "SFOData.EmpJobRelationships",
"uri": "EmpJobRelationships"
},
relationshipType: "3259", //current.subject_person_hr_profile.u_hr_manager.getDisplayValue(),
relUserId: current.subject_person_hr_profile.u_hr_manager.employee_number.getDisplayValue(),
userId: current.subject_person.employee_number.getDisplayValue(),
//personIdExternal: current.subject_person.employee_number.getDisplayValue(),
startDate: hireDate,
},
"cust_Returners": {
"__metadata": {
"type": "SFOData.cust_Returners",
"uri": "cust_Returners"
},
cust_CareerbreakdirectlybeforeBAT: iscareerbreak,
cust_lengthOfCareerBreak: lengthOfCB,
cust_Reasoncareer_break: cb_reason,
externalCode: current.subject_person.employee_number.getDisplayValue(),
},
}
};
gs.info("@@ data is " + JSON.stringify(data));
var request = new sn_ws.RESTMessageV2('BAT SNOW to EC Integration', 'Brazil new hire');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestBody(JSON.stringify(data));
var response = request.execute();
var responseBody = response.getBody();
var status = response.getStatusCode();
gs.info("@@## status code " + status);
gs.info('@@## response ' + responseBody);
if (!responseBody.includes('error')) {
current.work_notes = "Employee Profile has been created Successfully in SuccessFactors.";
// gs.infoMessage('After success message is received, please make sure you update the SF profile with the information under tab Payment information and Address Information.');
//gs.infoMessage('Ensure that Documentation is being stored in PeopleDoc as outlined in the case checklist');
} else if (status != 202) {
//gs.info('@@$$%%^^&*insideelseifStatus' + status);
current.work_notes = "There is Communication error. Please contact techical support team for more information.";
} else {
var firstJsonIndex = responseBody.indexOf('{');
var lastJsonIndex = responseBody.lastIndexOf('}') + 1;
//gs.info('lastJsonIndex' + " " + lastJsonIndex);
var finalJson = responseBody.substring(firstJsonIndex, lastJsonIndex);
//gs.info('finalJsonValuesAaya' + " " + finalJson);
finalJson = JSON.parse(finalJson);
if (finalJson.error != null) {
var errorCode = finalJson.error.code;
var errorMessage = finalJson.error.message.value;
//gs.info('errorCode' + " " + errorCode);
//gs.info('errorMessage' + " " + errorMessage);
current.autoSysFields(false);
current.setWorkflow(false);
current.u_error = true;
current.work_notes = errorMessage;
}
}
current.setWorkflow(false);
current.update();
//gs.info('CPI Status:' + " " + responseBody);
//gs.info('finalJson:' + " " + finalJson);
})(current, previous);Editor is loading...
Leave a Comment